|
202 | 202 | end |
203 | 203 |
|
204 | 204 | describe '#puppet_version' do |
205 | | - before(:all) do |
206 | | - @temp_puppet = Tempfile.new('puppet') |
207 | | - @temp_puppet.write "#!/bin/bash\n" |
208 | | - @temp_puppet.write "if [ \"$FAKE_PUPPET_VERSION\" == \"oops\" ]; then echo \"oops\" >&2; exit 1; fi\n" |
209 | | - @temp_puppet.write "echo $FAKE_PUPPET_VERSION\n" |
210 | | - @temp_puppet.close |
211 | | - FileUtils.chmod 0o755, @temp_puppet.path |
212 | | - end |
| 205 | + context 'with working Puppet version' do |
| 206 | + before(:all) do |
| 207 | + @temp_puppet = Tempfile.new('puppet') |
| 208 | + @temp_puppet.write "#!/bin/bash\n" |
| 209 | + @temp_puppet.write "echo '3.8.7'\n" |
| 210 | + @temp_puppet.close |
| 211 | + FileUtils.chmod 0o755, @temp_puppet.path |
| 212 | + end |
213 | 213 |
|
214 | | - after(:all) do |
215 | | - @temp_puppet.unlink |
216 | | - end |
| 214 | + after(:all) do |
| 215 | + @temp_puppet.unlink |
| 216 | + end |
217 | 217 |
|
218 | | - after(:each) do |
219 | | - ENV.delete('FAKE_PUPPET_VERSION') |
| 218 | + it 'should return a puppet version upon success' do |
| 219 | + opts = { |
| 220 | + basedir: '/', |
| 221 | + node: 'foonode', |
| 222 | + puppet_binary: @temp_puppet.path, |
| 223 | + puppet_command: @temp_puppet.path, |
| 224 | + fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
| 225 | + branch: '.' |
| 226 | + } |
| 227 | + catalog = OctocatalogDiff::Catalog::Computed.new(opts) |
| 228 | + catalog.build |
| 229 | + expect(catalog.puppet_version).to eq('3.8.7') |
| 230 | + end |
220 | 231 | end |
221 | 232 |
|
222 | | - it 'should return a puppet version upon success' do |
223 | | - ENV['FAKE_PUPPET_VERSION'] = '3.8.7' |
224 | | - opts = { |
225 | | - basedir: '/', |
226 | | - node: 'foonode', |
227 | | - pass_env_vars: ['FAKE_PUPPET_VERSION'], |
228 | | - puppet_binary: @temp_puppet.path, |
229 | | - puppet_command: @temp_puppet.path, |
230 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
231 | | - branch: '.' |
232 | | - } |
233 | | - catalog = OctocatalogDiff::Catalog::Computed.new(opts) |
234 | | - catalog.build |
235 | | - expect(catalog.puppet_version).to eq('3.8.7') |
236 | | - end |
| 233 | + context 'with failing Puppet version' do |
| 234 | + before(:all) do |
| 235 | + @temp_puppet = Tempfile.new('puppet') |
| 236 | + @temp_puppet.write "#!/bin/bash\n" |
| 237 | + @temp_puppet.write "echo 1>&2 'something failed horribly'\n" |
| 238 | + @temp_puppet.write "exit 1\n" |
| 239 | + @temp_puppet.close |
| 240 | + FileUtils.chmod 0o755, @temp_puppet.path |
| 241 | + end |
237 | 242 |
|
238 | | - it 'should raise an error if the version number is empty' do |
239 | | - opts = { |
240 | | - basedir: '/', |
241 | | - node: 'foonode', |
242 | | - puppet_binary: @temp_puppet.path, |
243 | | - puppet_command: @temp_puppet.path, |
244 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
245 | | - branch: '.' |
246 | | - } |
247 | | - expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
248 | | - .to raise_error(RuntimeError, /Unable to determine Puppet version/) |
249 | | - end |
| 243 | + after(:all) do |
| 244 | + @temp_puppet.unlink |
| 245 | + end |
250 | 246 |
|
251 | | - it 'should raise an error if the puppet binary is nil' do |
252 | | - opts = { |
253 | | - basedir: '/', |
254 | | - node: 'foonode', |
255 | | - puppet_command: @temp_puppet.path, |
256 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
257 | | - branch: '.' |
258 | | - } |
259 | | - expect { OctocatalogDiff::Catalog::Computed.new(opts).build }.to raise_error(ArgumentError) |
| 247 | + it 'should raise an error if the version number is empty' do |
| 248 | + opts = { |
| 249 | + basedir: '/', |
| 250 | + node: 'foonode', |
| 251 | + puppet_binary: @temp_puppet.path, |
| 252 | + puppet_command: @temp_puppet.path, |
| 253 | + fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
| 254 | + branch: '.' |
| 255 | + } |
| 256 | + expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
| 257 | + .to raise_error(RuntimeError, /Unable to determine Puppet version/) |
| 258 | + end |
260 | 259 | end |
| 260 | + end |
261 | 261 |
|
262 | | - it 'should raise an error if the puppet binary does not exist' do |
263 | | - ENV['FAKE_PUPPET_VERSION'] = 'chicken' |
264 | | - opts = { |
265 | | - basedir: '/', |
266 | | - node: 'foonode', |
267 | | - pass_env_vars: ['FAKE_PUPPET_VERSION'], |
268 | | - puppet_binary: '/alsdfklafjasfkljafjafkjsdflaksfjasdfjadsfjadsf', |
269 | | - puppet_command: @temp_puppet.path, |
270 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
271 | | - branch: '.' |
272 | | - } |
273 | | - expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
274 | | - .to raise_error(Errno::ENOENT) |
275 | | - end |
| 262 | + it 'should raise an error if the puppet binary is nil' do |
| 263 | + opts = { |
| 264 | + basedir: '/', |
| 265 | + node: 'foonode', |
| 266 | + puppet_command: '/alsdfklafjasfkljafjafkjsdflaksfjasdfjadsfjadsf', |
| 267 | + fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
| 268 | + branch: '.' |
| 269 | + } |
| 270 | + expect { OctocatalogDiff::Catalog::Computed.new(opts).build }.to raise_error(ArgumentError) |
| 271 | + end |
276 | 272 |
|
277 | | - it 'should raise an error if the puppet binary returns a nonzero exit code' do |
278 | | - ENV['FAKE_PUPPET_VERSION'] = 'oops' |
279 | | - opts = { |
280 | | - basedir: '/', |
281 | | - node: 'foonode', |
282 | | - pass_env_vars: ['FAKE_PUPPET_VERSION'], |
283 | | - puppet_binary: @temp_puppet.path, |
284 | | - puppet_command: @temp_puppet.path, |
285 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
286 | | - branch: '.' |
287 | | - } |
288 | | - expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
289 | | - .to raise_error(RuntimeError, /Unable to determine Puppet version/) |
290 | | - end |
| 273 | + it 'should raise an error if the puppet binary does not exist' do |
| 274 | + opts = { |
| 275 | + basedir: '/', |
| 276 | + node: 'foonode', |
| 277 | + puppet_binary: '/alsdfklafjasfkljafjafkjsdflaksfjasdfjadsfjadsf', |
| 278 | + puppet_command: '/alsdfklafjasfkljafjafkjsdflaksfjasdfjadsfjadsf', |
| 279 | + fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
| 280 | + branch: '.' |
| 281 | + } |
| 282 | + expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
| 283 | + .to raise_error(Errno::ENOENT) |
291 | 284 | end |
292 | 285 | end |
293 | 286 |
|
|
0 commit comments