{"action":"created","issue":{"url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/256","labels_url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/256/labels{/name}","comments_url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/256/comments","events_url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/256/events","html_url":"https://github.com/rodjek/rspec-puppet/issues/256","id":57391402,"number":256,"title":"compile matcher doesn't honor facts when selecting a default provider","user":{"login":"geoffdavis","id":146506,"avatar_url":"https://avatars.githubusercontent.com/u/146506?v=3","gravatar_id":"","url":"https://api.github.com/users/geoffdavis","html_url":"https://github.com/geoffdavis","followers_url":"https://api.github.com/users/geoffdavis/followers","following_url":"https://api.github.com/users/geoffdavis/following{/other_user}","gists_url":"https://api.github.com/users/geoffdavis/gists{/gist_id}","starred_url":"https://api.github.com/users/geoffdavis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geoffdavis/subscriptions","organizations_url":"https://api.github.com/users/geoffdavis/orgs","repos_url":"https://api.github.com/users/geoffdavis/repos","events_url":"https://api.github.com/users/geoffdavis/events{/privacy}","received_events_url":"https://api.github.com/users/geoffdavis/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rodjek/rspec-puppet/labels/bug","name":"bug","color":"e10c02"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-11T23:01:55Z","updated_at":"2015-11-10T15:06:10Z","closed_at":null,"body":"Possibly related to GH-175, the compile matcher doesn't seem to take into account overridden facts when deciding which provider to use. I discovered this when testing a class that made use of the User type.\r\n\r\nOn my Mac, no matter what the osfamily fact was set to, the provider for Users was set to the OSX default of \"directoryservice\". Other matchers seem to work fine, such as \"contain_user\".\r\n\r\nMy workaround has been to set a pre_condition that overrides the automatic provider selection on a per-OS basis.\r\n\r\nHere's a simple example that tests provider specific behavior. Running this on my Mac results in the Mac's directoryservice provider being used for the User type, despite the facts being set on the context.\r\n\r\n```puppet\r\nclass users::test {\r\n  # Darwin cannot use managehome by default with directoryservice provider\r\n  $my_managehome = $::osfamily ? {\r\n    'Darwin' => false,\r\n    default => true,\r\n  }\r\n  file { '/home': ensure => directory }\r\n  user { 'testuser':\r\n    managehome => $my_managehome,\r\n    home => '/home/testuser',\r\n  }\r\n}\r\n```\r\n\r\n```ruby\r\nrequire 'puppetlabs_spec_helper/module_spec_helper'\r\ndescribe 'users::test', :type => :class do\r\n  [\r\n    { :operatingsystem => 'Darwin',\r\n      :osfamily => 'Darwin',\r\n      :kernel => 'Darwin',\r\n    },\r\n    { :operatingsystem => 'CentOS',\r\n      :osfamily => 'RedHat',\r\n      :kernel => 'Linux',\r\n    },\r\n    { :operatingsystem => 'Solaris',\r\n      :osfamily => 'Solaris',\r\n      :kernel => 'SunOS',\r\n    },\r\n  ].each do |f|\r\n    context \"On #{f[:operatingsystem]}\" do\r\n      let(:facts) { f }\r\n      it { should compile } # <-- this fails on the Solaris and Linux cases when run on a Mac\r\n      it { should contain_user('testuser') } # <-- this works all all three platforms\r\n    end\r\n  end  \r\nend\r\n```\r\n\r\nWhen these tests are run on a Mac, I get output like this:\r\n```\r\n$ rspec --color --format d spec/classes/users_test_spec.rb\r\n\r\nusers::test\r\n  On Darwin\r\n    should compile into a catalogue without dependency cycles\r\n    should contain User[testuser]\r\n  On CentOS\r\n    should compile into a catalogue without dependency cycles (FAILED - 1)\r\n    should contain User[testuser]\r\n  On Solaris\r\n    should compile into a catalogue without dependency cycles (FAILED - 2)\r\n    should contain User[testuser]\r\n\r\nFailures:\r\n\r\n  1) users::test On CentOS should compile into a catalogue without dependency cycles\r\n     Failure/Error: it { should compile } # <-- this fails on the Solaris and Linux cases when run on a Mac\r\n       error during compilation: Parameter managehome failed on User[testuser]: User provider directoryservice can not manage home directories at modules/users/spec/fixtures/modules/users/manifests/test.pp:11\r\n     # ./spec/classes/users_test_spec.rb:20:in `block (4 levels) in <top (required)>'\r\n\r\n  2) users::test On Solaris should compile into a catalogue without dependency cycles\r\n     Failure/Error: it { should compile } # <-- this fails on the Solaris and Linux cases when run on a Mac\r\n       error during compilation: Parameter managehome failed on User[testuser]: User provider directoryservice can not manage home directories at modules/users/spec/fixtures/modules/users/manifests/test.pp:11\r\n     # ./spec/classes/users_test_spec.rb:20:in `block (4 levels) in <top (required)>'\r\n\r\nFinished in 0.6555 seconds\r\n6 examples, 2 failures\r\n\r\nFailed examples:\r\n\r\nrspec ./spec/classes/users_test_spec.rb:20 # users::test On CentOS should compile into a catalogue without dependency cycles\r\nrspec ./spec/classes/users_test_spec.rb:20 # users::test On Solaris should compile into a catalogue without dependency cycles\r\n```\r\n\r\nAs seen in the Failures section, the provider 'directoryservice' is being used on all three platforms. I'm able to manually specify an appropriate provider for the User type for each platform and this problem goes away.\r\n\r\nFinally, here are the Gems I'm using for this test. I tested with rspec-puppet 2.0.0 and 1.0.1\r\n\r\n```\r\n$ bundle\r\nUsing rake 10.4.2\r\nUsing CFPropertyList 2.2.8\r\nUsing builder 3.2.2\r\nUsing ci_reporter 2.0.0\r\nUsing rspec-core 2.99.2\r\nUsing diff-lcs 1.2.5\r\nUsing rspec-expectations 2.99.2\r\nUsing rspec-mocks 2.99.3\r\nUsing rspec 2.99.0\r\nUsing ci_reporter_rspec 1.0.0\r\nUsing facter 2.3.0\r\nUsing git 1.2.9.1\r\nUsing json_pure 1.8.2\r\nUsing hiera 1.3.4\r\nUsing metaclass 0.0.4\r\nUsing mocha 1.1.0\r\nUsing puppet 3.7.3\r\nUsing puppet-lint 1.1.0\r\nUsing puppet-syntax 1.4.1\r\nUsing rspec-puppet 2.0.0\r\nUsing puppetlabs_spec_helper 0.8.2\r\nUsing bundler 1.7.4\r\n```\r\n\r\nIt would be nice if the osfamily and operatingsystem facts were respected by the compile matcher at least in terms of default provider selection."},"comment":{"url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/comments/155445175","html_url":"https://github.com/rodjek/rspec-puppet/issues/256#issuecomment-155445175","issue_url":"https://api.github.com/repos/rodjek/rspec-puppet/issues/256","id":155445175,"user":{"login":"queeno","id":1544527,"avatar_url":"https://avatars.githubusercontent.com/u/1544527?v=3","gravatar_id":"","url":"https://api.github.com/users/queeno","html_url":"https://github.com/queeno","followers_url":"https://api.github.com/users/queeno/followers","following_url":"https://api.github.com/users/queeno/following{/other_user}","gists_url":"https://api.github.com/users/queeno/gists{/gist_id}","starred_url":"https://api.github.com/users/queeno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/queeno/subscriptions","organizations_url":"https://api.github.com/users/queeno/orgs","repos_url":"https://api.github.com/users/queeno/repos","events_url":"https://api.github.com/users/queeno/events{/privacy}","received_events_url":"https://api.github.com/users/queeno/received_events","type":"User","site_admin":false},"created_at":"2015-11-10T15:06:10Z","updated_at":"2015-11-10T15:06:10Z","body":"Hey @xaniasd \r\n\r\nUnfortunately adding a default provider in the Package resource won't work, if the elasticsearch module sets it to undef.\r\n\r\nI believe you have a couple of options:\r\n\r\n- You could attempt to induce rspec-puppet into believing that the running OS is not OSX adding something like this in your `spec_helper.rb` file:\r\n  \r\n  ```\r\n  RSpec.configure do |c|\r\n    c.default_facts = {\r\n      :operatingsystem        => 'CentOS',\r\n      :operatingsystemrelease => '6.6',\r\n      :osfamily               => 'RedHat',\r\n    }\r\n  end\r\n  ```\r\n  This might not work though, because I believe puppet picks the default provider for the package type calling the Facter module directly. In that case, you might consider ways of tricking facter to return a different OS name. However this might break other modules.\r\n\r\n- Another option you have is to fork the elasticsearch module and edit it so it never explicitly creates package resources with `provider => undef`.\r\n  \r\n  Instead this:\r\n  ```\r\n    if ($::operatingsystem == 'OpenSuSE') {\r\n      $pkg_provider = 'rpm'\r\n    } else {\r\n      $pkg_provider = undef\r\n    }\r\n  ```\r\n  you could completely scrap the `$pkg_provider` variable and set a provider default, if the operating system is OpenSuSE. The code will also look much neater! (I might open a pull request with them if I have some time later ;) )\r\n  \r\n  ```\r\n  if ($::operatingsystem == 'OpenSuSE') {\r\n    Package {\r\n      provider => 'rpm'\r\n    }\r\n  }\r\n  ```"}}