diff options
-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 |