Skip to content

Flip installed and present in Function ensure_packages #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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