1 require 'spec_helper_acceptance'
3 tmpdir = default.tmpdir('tmp')
5 describe 'ini_setting resource' do
7 shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0, 1, 2])
10 shared_examples 'has_content' do |path, pp, content|
12 shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
15 shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
16 shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
19 it 'applies the manifest twice' do
20 apply_manifest(pp, :catch_failures => true)
21 apply_manifest(pp, :catch_changes => true)
24 describe file(path) do
26 its(:content) { should match content }
30 shared_examples 'has_error' do |path, pp, error|
32 shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
35 shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
36 shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
39 it 'applies the manifest and gets a failure message' do
40 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(error)
43 describe file(path) do
44 it { should_not be_file }
48 describe 'ensure parameter' do
49 context '=> present for global and section' do
51 ini_setting { 'ensure => present for section':
53 path => "#{tmpdir}/ini_setting.ini",
58 ini_setting { 'ensure => present for global':
60 path => "#{tmpdir}/ini_setting.ini",
67 it 'applies the manifest twice' do
68 apply_manifest(pp, :catch_failures => true)
69 apply_manifest(pp, :catch_changes => true)
72 it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, /four = five\n\n\[one\]\ntwo = three/
75 context '=> absent for key/value' do
77 if fact('osfamily') == 'Darwin'
78 shell("echo \"four = five[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
80 shell("echo -e \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
85 ini_setting { 'ensure => absent for key/value':
87 path => "#{tmpdir}/ini_setting.ini",
94 it 'applies the manifest twice' do
95 apply_manifest(pp, :catch_failures => true)
96 apply_manifest(pp, :catch_changes => true)
99 describe file("#{tmpdir}/ini_setting.ini") do
100 it { should be_file }
102 should match /four = five/
103 should match /\[one\]/
104 should_not match /two = three/
109 context '=> absent for global' do
111 if fact('osfamily') == 'Darwin'
112 shell("echo \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
114 shell("echo -e \"four = five\n[one]\ntwo = three\" > #{tmpdir}/ini_setting.ini")
118 shell("cat #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0, 1, 2])
119 shell("rm #{tmpdir}/ini_setting.ini", :acceptable_exit_codes => [0, 1, 2])
123 ini_setting { 'ensure => absent for global':
125 path => "#{tmpdir}/ini_setting.ini",
132 it 'applies the manifest twice' do
133 apply_manifest(pp, :catch_failures => true)
134 apply_manifest(pp, :catch_changes => true)
137 describe file("#{tmpdir}/ini_setting.ini") do
138 it { should be_file }
140 should_not match /four = five/
141 should match /\[one\]/
142 should match /two = three/
148 describe 'section, setting, value parameters' do
150 "section => 'test', setting => 'foo', value => 'bar'," => /\[test\]\nfoo = bar/,
151 "section => 'more', setting => 'baz', value => 'quux'," => /\[more\]\nbaz = quux/,
152 "section => '', setting => 'top', value => 'level'," => /top = level/,
153 "section => 'z', setting => 'sp aces', value => 'foo bar'," => /\[z\]\nsp aces = foo bar/,
154 }.each do |parameter_list, content|
155 context parameter_list do
157 ini_setting { "#{parameter_list}":
159 path => "#{tmpdir}/ini_setting.ini",
164 it_behaves_like 'has_content', "#{tmpdir}/ini_setting.ini", pp, content
169 "section => 'test'," => /setting is a required.+value is a required/,
170 "setting => 'foo', value => 'bar'," => /section is a required/,
171 "section => 'test', setting => 'foo'," => /value is a required/,
172 "section => 'test', value => 'bar'," => /setting is a required/,
173 "value => 'bar'," => /section is a required.+setting is a required/,
174 "setting => 'foo'," => /section is a required.+value is a required/,
175 }.each do |parameter_list, error|
176 context parameter_list, :pending => 'no error checking yet' do
178 ini_setting { "#{parameter_list}":
180 path => "#{tmpdir}/ini_setting.ini",
185 it_behaves_like 'has_error', "#{tmpdir}/ini_setting.ini", pp, error
190 describe 'path parameter' do
194 "#{tmpdir}/three.ini",
196 context "path => #{path}" do
198 ini_setting { 'path => #{path}':
207 it_behaves_like 'has_content', path, pp, /\[one\]\ntwo = three/
211 context "path => foo" do
213 ini_setting { 'path => foo':
222 it_behaves_like 'has_error', 'foo', pp, /must be fully qualified/
226 describe 'key_val_separator parameter' do
229 "key_val_separator => '='," => /two=three/,
230 "key_val_separator => ' = '," => /two = three/,
231 }.each do |parameter, content|
232 context "with \"#{parameter}\" makes \"#{content}\"" do
234 ini_setting { "with #{parameter} makes #{content}":
239 path => "#{tmpdir}/key_val_separator.ini",
244 it_behaves_like 'has_content', "#{tmpdir}/key_val_separator.ini", pp, content