Skip to content

Commit 2fbeac2

Browse files
committed
Merge pull request #185 from danzilio/create_ini_settings_namespace
Adding path to create_ini_settings resources
2 parents 7e05272 + 54f12d3 commit 2fbeac2

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

lib/puppet/parser/functions/create_ini_settings.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ module Puppet::Parser::Functions
2424
2525
Will create the following resources
2626
27-
ini_setting{'[section1] setting1':
27+
ini_setting{'/tmp/foo.ini [section1] setting1':
2828
ensure => present,
2929
section => 'section1',
3030
setting => 'setting1',
3131
value => 'val1',
3232
path => '/tmp/foo.ini',
3333
}
34-
ini_setting{'[section2] setting2':
34+
ini_setting{'/tmp/foo.ini [section2] setting2':
3535
ensure => present,
3636
section => 'section2',
3737
setting => 'setting2',
3838
value => 'val2',
3939
path => '/tmp/foo.ini',
4040
}
41-
ini_setting{'[section2] setting3':
41+
ini_setting{'/tmp/foo.ini [section2] setting3':
4242
ensure => absent,
4343
section => 'section2',
4444
setting => 'setting3',
@@ -64,8 +64,12 @@ module Puppet::Parser::Functions
6464
"create_ini_settings(): Section #{section} must contain a Hash") \
6565
unless settings[section].is_a?(Hash)
6666

67+
unless path = defaults.merge(settings)['path']
68+
raise Puppet::ParseError, 'create_ini_settings(): must pass the path parameter to the Ini_setting resource!'
69+
end
70+
6771
settings[section].each do |setting, value|
68-
res["[#{section}] #{setting}"] = {
72+
res["#{path} [#{section}] #{setting}"] = {
6973
'ensure' => 'present',
7074
'section' => section,
7175
'setting' => setting,

spec/classes/create_ini_settings_test_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
# end-to-end test of the create_init_settings function
33
describe 'create_ini_settings_test' do
44
it { should have_ini_setting_resource_count(3) }
5-
it { should contain_ini_setting('[section1] setting1').with(
5+
it { should contain_ini_setting('/tmp/foo.ini [section1] setting1').with(
66
:ensure => 'present',
77
:section => 'section1',
88
:setting => 'setting1',
99
:value => 'val1',
1010
:path => '/tmp/foo.ini'
1111
)}
12-
it { should contain_ini_setting('[section2] setting2').with(
12+
it { should contain_ini_setting('/tmp/foo.ini [section2] setting2').with(
1313
:ensure => 'present',
1414
:section => 'section2',
1515
:setting => 'setting2',
1616
:value => 'val2',
1717
:path => '/tmp/foo.ini'
1818
)}
19-
it { should contain_ini_setting('[section2] setting3').with(
19+
it { should contain_ini_setting('/tmp/foo.ini [section2] setting3').with(
2020
:ensure => 'absent',
2121
:section => 'section2',
2222
:setting => 'setting3',

spec/functions/create_ini_settings_spec.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
end
1111

1212
describe 'argument handling' do
13-
it { should run.with_params.and_raise_error(Puppet::ParseError, /0 for 1 or 2/) }
14-
it { should run.with_params(1,2,3).and_raise_error(Puppet::ParseError, /3 for 1 or 2/) }
15-
it { should run.with_params('foo').and_raise_error(Puppet::ParseError, /Requires all arguments/) }
16-
it { should run.with_params({},'foo').and_raise_error(Puppet::ParseError, /Requires all arguments/) }
13+
it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, /0 for 1 or 2/) }
14+
it { is_expected.to run.with_params(1,2,3).and_raise_error(Puppet::ParseError, /3 for 1 or 2/) }
15+
it { is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError, /Requires all arguments/) }
16+
it { is_expected.to run.with_params({},'foo').and_raise_error(Puppet::ParseError, /Requires all arguments/) }
1717

18-
it { should run.with_params({}) }
19-
it { should run.with_params({},{}) }
18+
it { is_expected.to run.with_params({}) }
19+
it { is_expected.to run.with_params({},{}) }
2020

21-
it { should run.with_params({ 1 => 2 }).and_raise_error(Puppet::ParseError, /Section 1 must contain a Hash/) }
21+
it { is_expected.to run.with_params({ 'section' => { 'setting' => 'value' }}).and_raise_error(Puppet::ParseError, /must pass the path parameter/) }
22+
it { is_expected.to run.with_params({ 1 => 2 }).and_raise_error(Puppet::ParseError, /Section 1 must contain a Hash/) }
2223
end
2324
end

0 commit comments

Comments
 (0)