diff options
author | John Keiser <john@johnkeiser.com> | 2015-09-25 17:46:30 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-09-28 17:34:54 -0700 |
commit | fd01105a5214cf90eea59c09d4fce14f0abb586e (patch) | |
tree | 48204d3276d17a3b8b002ca9102a5086bdb44418 /spec/unit/provider_resolver_spec.rb | |
parent | 857b159344ccbc07af06d45854eb8b2f6dc77d11 (diff) | |
download | chef-fd01105a5214cf90eea59c09d4fce14f0abb586e.tar.gz |
Test more of provider resolution by mocking the filesystem and commands
Diffstat (limited to 'spec/unit/provider_resolver_spec.rb')
-rw-r--r-- | spec/unit/provider_resolver_spec.rb | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb index 88df4a20cc..aa485d1fe1 100644 --- a/spec/unit/provider_resolver_spec.rb +++ b/spec/unit/provider_resolver_spec.rb @@ -20,6 +20,7 @@ require 'spec_helper' require 'chef/mixin/convert_to_class_name' require 'chef/provider_resolver' require 'chef/platform/service_helpers' +require 'support/shared/unit/double_world' include Chef::Mixin::ConvertToClassName @@ -27,6 +28,7 @@ include Chef::Mixin::ConvertToClassName #module Chef::Provider describe Chef::ProviderResolver do + include_context "double world" let(:resource_name) { :service } let(:provider) { nil } @@ -139,9 +141,37 @@ describe Chef::ProviderResolver do end def stub_service_configs(*configs) - configs ||= [] - allow(Chef::Platform::ServiceHelpers).to receive(:config_for_service).with("ntp") - .and_return(configs) + configs.each do |config| + case config + when :initd + world.files["/etc/init.d/test"] ||= "" + when :upstart + world.files["/etc/init/test.conf"] ||= "" + when :xinetd + world.files["/etc/xinetd.d/test"] ||= "" + when :etc_rcd + world.files["/etc/rc.d/test"] ||= "" + when :usr_local_etc_rcd + world.files["/usr/local/etc/rc.d/test"] ||= "" + when :systemd + world.files["/bin/systemd"] ||= "" + world.files["/proc/1/comm"] ||= "systemd\n" + world.commands["/bin/systemd --all"] ||= <<-EOM +superv loaded +stinky something-else +test loaded +blargh not-found +EOM + world.commands["/bin/systemd list-unit-files"] ||= <<-EOM +usuperv loaded +ustinky something-else +utest loaded +ublargh not-found +EOM + else + raise ArgumentError, config + end + end end before do @@ -413,7 +443,7 @@ describe Chef::ProviderResolver do it "always returns a Solaris provider" do # no matter what we stub on the next two lines we should get a Solaris provider stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:initd, :upstart, :xinetd, :user_local_etc_rcd, :systemd) + stub_service_configs(:initd, :upstart, :xinetd, :usr_local_etc_rcd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Solaris) end end @@ -428,7 +458,7 @@ describe Chef::ProviderResolver do it "always returns a Windows provider" do # no matter what we stub on the next two lines we should get a Windows provider stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:initd, :upstart, :xinetd, :user_local_etc_rcd, :systemd) + stub_service_configs(:initd, :upstart, :xinetd, :usr_local_etc_rcd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Windows) end end @@ -443,7 +473,7 @@ describe Chef::ProviderResolver do it "always returns a Macosx provider" do # no matter what we stub on the next two lines we should get a Macosx provider stub_service_providers(:debian, :invokercd, :insserv, :upstart, :redhat, :systemd) - stub_service_configs(:initd, :upstart, :xinetd, :user_local_etc_rcd, :systemd) + stub_service_configs(:initd, :upstart, :xinetd, :usr_local_etc_rcd, :systemd) expect(resolved_provider).to eql(Chef::Provider::Service::Macosx) end end |