1 require 'spec_helper_acceptance'
3 tmpdir = default.tmpdir('tmp')
5 describe 'ini_subsetting 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
32 shared_examples 'has_error' do |path, pp, error|
34 shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
37 shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
38 shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
41 it 'applies the manifest and gets a failure message' do
42 expect(apply_manifest(pp, :expect_failures => true).stderr).to match(error)
45 describe file(path) do
46 it { should_not be_file }
50 describe 'ensure, section, setting, subsetting, & value parameters' do
51 context '=> present with subsections' do
53 ini_subsetting { 'ensure => present for alpha':
55 path => "#{tmpdir}/ini_subsetting.ini",
58 subsetting => 'alpha',
61 ini_subsetting { 'ensure => present for beta':
63 path => "#{tmpdir}/ini_subsetting.ini",
68 require => Ini_subsetting['ensure => present for alpha'],
72 it 'applies the manifest twice' do
73 apply_manifest(pp, :catch_failures => true)
74 apply_manifest(pp, :catch_changes => true)
77 describe file("#{tmpdir}/ini_subsetting.ini") do
80 should match /\[one\]\nkey = alphabet betatrons/
85 context 'ensure => absent' do
87 if fact('osfamily') == 'Darwin'
88 shell("echo \"[one]\nkey = alphabet betatrons\" > #{tmpdir}/ini_subsetting.ini")
90 shell("echo -e \"[one]\nkey = alphabet betatrons\" > #{tmpdir}/ini_subsetting.ini")
95 ini_subsetting { 'ensure => absent for subsetting':
97 path => "#{tmpdir}/ini_subsetting.ini",
100 subsetting => 'alpha',
104 it 'applies the manifest twice' do
105 apply_manifest(pp, :catch_failures => true)
106 apply_manifest(pp, :catch_changes => true)
109 describe file("#{tmpdir}/ini_subsetting.ini") do
110 it { should be_file }
112 should match /\[one\]/
113 should match /key = betatrons/
114 should_not match /alphabet/
120 describe 'subsetting_separator' do
122 "" => /two = twinethree foobar/,
123 "subsetting_separator => ','," => /two = twinethree,foobar/,
124 "subsetting_separator => ' '," => /two = twinethree foobar/,
125 "subsetting_separator => ' == '," => /two = twinethree == foobar/,
126 "subsetting_separator => '='," => /two = twinethree=foobar/,
127 }.each do |parameter, content|
128 context "with \"#{parameter}\" makes \"#{content}\"" do
130 ini_subsetting { "with #{parameter} makes #{content}":
134 subsetting => 'twine',
136 path => "#{tmpdir}/subsetting_separator.ini",
137 before => Ini_subsetting['foobar'],
140 ini_subsetting { "foobar":
146 path => "#{tmpdir}/subsetting_separator.ini",
151 it_behaves_like 'has_content', "#{tmpdir}/subsetting_separator.ini", pp, content
156 describe 'quote_char' do
158 ['-Xmx'] => /args=""/,
159 ['-Xmx', '256m'] => /args=-Xmx256m/,
160 ['-Xmx', '512m'] => /args="-Xmx512m"/,
161 ['-Xms', '256m'] => /args="-Xmx256m -Xms256m"/,
162 }.each do |parameter, content|
163 context %Q{with '#{parameter.first}' #{parameter.length > 1 ? '=> \'' << parameter[1] << '\'' : 'absent'} makes '#{content}'} do
164 path = File.join(tmpdir, 'ini_subsetting.ini')
167 shell(%Q{echo '[java]\nargs=-Xmx256m' > #{path}})
170 shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
171 shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
175 ini_subsetting { '#{parameter.first}':
176 ensure => #{parameter.length > 1 ? 'present' : 'absent'},
181 subsetting => '#{parameter.first}',
182 value => '#{parameter.length > 1 ? parameter[1] : ''}'
186 it 'applies the manifest twice' do
187 apply_manifest(pp, :catch_failures => true)
188 apply_manifest(pp, :catch_changes => true)
191 describe file("#{tmpdir}/ini_subsetting.ini") do
192 it { should be_file }