Skip to content

Commit

Permalink
Merge pull request #1196 from cocker-cc/Fix_ensure_packages
Browse files Browse the repository at this point in the history
Fix ensure_packages
  • Loading branch information
adrianiurca authored Aug 9, 2021
2 parents ba0345e + 77a9c07 commit 842992e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions lib/puppet/parser/functions/ensure_packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ module Puppet::Parser::Functions

if arguments[0].is_a?(Hash)
if arguments[1]
defaults = { 'ensure' => 'present' }.merge(arguments[1])
if defaults['ensure'] == 'installed'
defaults['ensure'] = 'present'
defaults = { 'ensure' => 'installed' }.merge(arguments[1])
if defaults['ensure'] == 'present'
defaults['ensure'] = 'installed'
end
else
defaults = { 'ensure' => 'present' }
defaults = { 'ensure' => 'installed' }
end

Puppet::Parser::Functions.function(:ensure_resources)
Expand All @@ -34,12 +34,12 @@ module Puppet::Parser::Functions
packages = Array(arguments[0])

if arguments[1]
defaults = { 'ensure' => 'present' }.merge(arguments[1])
if defaults['ensure'] == 'installed'
defaults['ensure'] = 'present'
defaults = { 'ensure' => 'installed' }.merge(arguments[1])
if defaults['ensure'] == 'present'
defaults['ensure'] = 'installed'
end
else
defaults = { 'ensure' => 'present' }
defaults = { 'ensure' => 'installed' }
end

Puppet::Parser::Functions.function(:ensure_resource)
Expand Down
18 changes: 9 additions & 9 deletions spec/functions/ensure_packages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@

# this lambda is required due to strangeness within rspec-puppet's expectation handling
it { expect(-> { catalogue }).to contain_package('puppet').with_ensure('absent') }
it { expect(-> { catalogue }).to contain_package('facter').with_ensure('present') }
it { expect(-> { catalogue }).to contain_package('facter').with_ensure('installed') }
end

describe 'after running ensure_package("facter", { "provider" => "gem" })' do
before(:each) { subject.execute('facter', 'provider' => 'gem') }

# this lambda is required due to strangeness within rspec-puppet's expectation handling
it { expect(-> { catalogue }).to contain_package('puppet').with_ensure('absent').without_provider }
it { expect(-> { catalogue }).to contain_package('facter').with_ensure('present').with_provider('gem') }
it { expect(-> { catalogue }).to contain_package('facter').with_ensure('installed').with_provider('gem') }
end
end

Expand All @@ -52,23 +52,23 @@
end

# this lambda is required due to strangeness within rspec-puppet's expectation handling
it { expect(-> { catalogue }).to contain_package('foo').with('provider' => 'rpm', 'ensure' => 'present') }
it { expect(-> { catalogue }).to contain_package('bar').with('provider' => 'gem', 'ensure' => 'present') }
it { expect(-> { catalogue }).to contain_package('foo').with('provider' => 'rpm', 'ensure' => 'installed') }
it { expect(-> { catalogue }).to contain_package('bar').with('provider' => 'gem', 'ensure' => 'installed') }

context 'with UTF8 and double byte characters' do
it { expect(-> { catalogue }).to contain_package('パッケージ').with('ensure' => 'absent') }
it { expect(-> { catalogue }).to contain_package('ρǻ¢κầģẻ').with('ensure' => 'absent') }
end
end

context 'when given a catalog with "package { puppet: ensure => present }"' do
let(:pre_condition) { 'package { puppet: ensure => present }' }
context 'when given a catalog with "package { puppet: ensure => installed }"' do
let(:pre_condition) { 'package { puppet: ensure => installed }' }

describe 'after running ensure_package("puppet", { "ensure" => "installed" })' do
before(:each) { subject.execute('puppet', 'ensure' => 'installed') }
describe 'after running ensure_package("puppet", { "ensure" => "present" })' do
before(:each) { subject.execute('puppet', 'ensure' => 'present') }

# this lambda is required due to strangeness within rspec-puppet's expectation handling
it { expect(-> { catalogue }).to contain_package('puppet').with_ensure('present') }
it { expect(-> { catalogue }).to contain_package('puppet').with_ensure('installed') }
end
end
end

0 comments on commit 842992e

Please sign in to comment.