diff options
author | Tyler Ball <tyleraball@gmail.com> | 2014-10-13 13:58:09 -0500 |
---|---|---|
committer | Tyler Ball <tyleraball@gmail.com> | 2014-10-13 13:58:09 -0500 |
commit | 87ebd29a5632d4a2598b12b99ecc9d2ee2b4586f (patch) | |
tree | d8c29af59da6cc228a6dfbeae133f9fe92fed788 | |
parent | 57b6b93cfe8f32e30c03503d1facf9fac011842c (diff) | |
parent | 4cb27331d81b394b816278e2bed6b3395b54b9c9 (diff) | |
download | chef-87ebd29a5632d4a2598b12b99ecc9d2ee2b4586f.tar.gz |
Merge pull request #2215 from opscode/tball/homebrew_fix
Fixing bug where tried to use the homebrew provider on OSX and didn't correctly check for lack of homebrew-specific attribute on the resource
-rw-r--r-- | lib/chef/mixin/homebrew_user.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/package/homebrew.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/package/homebrew_spec.rb | 9 |
3 files changed, 11 insertions, 2 deletions
diff --git a/lib/chef/mixin/homebrew_user.rb b/lib/chef/mixin/homebrew_user.rb index 854a954a90..ab6fb19563 100644 --- a/lib/chef/mixin/homebrew_user.rb +++ b/lib/chef/mixin/homebrew_user.rb @@ -36,7 +36,7 @@ class Chef # the brew executable. def find_homebrew_uid(provided_user = nil) # They could provide us a user name or a UID - unless provided_user.nil? + if provided_user return provided_user if provided_user.is_a? Integer return Etc.getpwnam(provided_user).uid end diff --git a/lib/chef/provider/package/homebrew.rb b/lib/chef/provider/package/homebrew.rb index 202e4d2533..a9aeea1415 100644 --- a/lib/chef/provider/package/homebrew.rb +++ b/lib/chef/provider/package/homebrew.rb @@ -109,7 +109,7 @@ class Chef private def get_response_from_command(command) - homebrew_uid = find_homebrew_uid(new_resource.homebrew_user) + homebrew_uid = find_homebrew_uid(new_resource.respond_to?(:homebrew_user) && new_resource.homebrew_user) homebrew_user = Etc.getpwuid(homebrew_uid) Chef::Log.debug "Executing '#{command}' as user '#{homebrew_user.name}'" diff --git a/spec/unit/provider/package/homebrew_spec.rb b/spec/unit/provider/package/homebrew_spec.rb index d38458546d..dccd8edf11 100644 --- a/spec/unit/provider/package/homebrew_spec.rb +++ b/spec/unit/provider/package/homebrew_spec.rb @@ -158,6 +158,15 @@ describe Chef::Provider::Package::Homebrew do allow(provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => 'homestarrunner')) expect(provider.brew('info', 'opts', 'bananas')).to eql('homestarrunner') end + + context "when new_resource is Package" do + let(:new_resource) { Chef::Resource::Package.new('emacs') } + + it "does not try to read homebrew_user from Package, which does not have it" do + allow(provider).to receive(:shell_out!).and_return(OpenStruct.new(:stdout => 'zombo')) + expect(provider.brew).to eql('zombo') + end + end end context 'when testing actions' do |