forked from puppetlabs/puppetlabs-inifile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathini_subsetting_spec.rb
More file actions
198 lines (176 loc) · 5.91 KB
/
ini_subsetting_spec.rb
File metadata and controls
198 lines (176 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
require 'spec_helper_acceptance'
tmpdir = default.tmpdir('tmp')
describe 'ini_subsetting resource' do
after :all do
shell("rm #{tmpdir}/*.ini", :acceptable_exit_codes => [0, 1, 2])
end
shared_examples 'has_content' do |path, pp, content|
before :all do
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
end
after :all do
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
end
it 'applies the manifest twice' do
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file(path) do
it { should be_file }
its(:content) {
should match content
}
end
end
shared_examples 'has_error' do |path, pp, error|
before :all do
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
end
after :all do
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
end
it 'applies the manifest and gets a failure message' do
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(error)
end
describe file(path) do
it { should_not be_file }
end
end
describe 'ensure, section, setting, subsetting, & value parameters' do
context '=> present with subsections' do
pp = <<-EOS
ini_subsetting { 'ensure => present for alpha':
ensure => present,
path => "#{tmpdir}/ini_subsetting.ini",
section => 'one',
setting => 'key',
subsetting => 'alpha',
value => 'bet',
}
ini_subsetting { 'ensure => present for beta':
ensure => present,
path => "#{tmpdir}/ini_subsetting.ini",
section => 'one',
setting => 'key',
subsetting => 'beta',
value => 'trons',
}
EOS
it 'applies the manifest twice' do
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/ini_subsetting.ini") do
it { should be_file }
its(:content) {
should match /\[one\]\nkey = alphabet betatrons/
}
end
end
context 'ensure => absent' do
before :all do
if fact('osfamily') == 'Darwin'
shell("echo \"[one]\nkey = alphabet betatrons\" > #{tmpdir}/ini_subsetting.ini")
else
shell("echo -e \"[one]\nkey = alphabet betatrons\" > #{tmpdir}/ini_subsetting.ini")
end
end
pp = <<-EOS
ini_subsetting { 'ensure => absent for subsetting':
ensure => absent,
path => "#{tmpdir}/ini_subsetting.ini",
section => 'one',
setting => 'key',
subsetting => 'alpha',
}
EOS
it 'applies the manifest twice' do
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/ini_subsetting.ini") do
it { should be_file }
its(:content) {
should match /\[one\]/
should match /key = betatrons/
should_not match /alphabet/
}
end
end
end
describe 'subsetting_separator' do
{
"" => /two = twinethree foobar/,
"subsetting_separator => ','," => /two = twinethree,foobar/,
"subsetting_separator => ' '," => /two = twinethree foobar/,
"subsetting_separator => ' == '," => /two = twinethree == foobar/,
"subsetting_separator => '='," => /two = twinethree=foobar/,
}.each do |parameter, content|
context "with \"#{parameter}\" makes \"#{content}\"" do
pp = <<-EOS
ini_subsetting { "with #{parameter} makes #{content}":
ensure => present,
section => 'one',
setting => 'two',
subsetting => 'twine',
value => 'three',
path => "#{tmpdir}/subsetting_separator.ini",
#{parameter}
}
ini_subsetting { "foobar":
ensure => present,
section => 'one',
setting => 'two',
subsetting => 'foo',
value => 'bar',
path => "#{tmpdir}/subsetting_separator.ini",
#{parameter}
}
EOS
it_behaves_like 'has_content', "#{tmpdir}/subsetting_separator.ini", pp, content
end
end
end
describe 'quote_char' do
{
['-Xmx'] => /args=""/,
['-Xmx', '256m'] => /args=-Xmx256m/,
['-Xmx', '512m'] => /args="-Xmx512m"/,
['-Xms', '256m'] => /args="-Xmx256m -Xms256m"/,
}.each do |parameter, content|
context %Q{with '#{parameter.first}' #{parameter.length > 1 ? '=> \'' << parameter[1] << '\'' : 'absent'} makes '#{content}'} do
path = File.join(tmpdir, 'ini_subsetting.ini')
before :all do
shell(%Q{echo '[java]\nargs=-Xmx256m' > #{path}})
end
after :all do
shell("cat #{path}", :acceptable_exit_codes => [0, 1, 2])
shell("rm #{path}", :acceptable_exit_codes => [0, 1, 2])
end
pp = <<-EOS
ini_subsetting { '#{parameter.first}':
ensure => #{parameter.length > 1 ? 'present' : 'absent'},
path => '#{path}',
section => 'java',
setting => 'args',
quote_char => '"',
subsetting => '#{parameter.first}',
value => '#{parameter.length > 1 ? parameter[1] : ''}'
}
EOS
it 'applies the manifest twice' do
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
describe file("#{tmpdir}/ini_subsetting.ini") do
it { should be_file }
its(:content) {
should match content
}
end
end
end
end
end