|
239 | 239 | end |
240 | 240 |
|
241 | 241 | describe '#puppet_version' do |
242 | | - before(:all) do |
243 | | - @temp_puppet = Tempfile.new('puppet') |
244 | | - @temp_puppet.write "#!/bin/bash\n" |
245 | | - @temp_puppet.write "if [ \"$FAKE_PUPPET_VERSION\" == \"oops\" ]; then echo \"oops\" >&2; exit 1; fi\n" |
246 | | - @temp_puppet.write "echo $FAKE_PUPPET_VERSION\n" |
247 | | - @temp_puppet.close |
248 | | - FileUtils.chmod 0o755, @temp_puppet.path |
249 | | - end |
| 242 | + context 'with working Puppet version' do |
| 243 | + before(:all) do |
| 244 | + @temp_puppet = Tempfile.new('puppet') |
| 245 | + @temp_puppet.write "#!/bin/bash\n" |
| 246 | + @temp_puppet.write "echo '3.8.7'\n" |
| 247 | + @temp_puppet.close |
| 248 | + FileUtils.chmod 0o755, @temp_puppet.path |
| 249 | + end |
250 | 250 |
|
251 | | - after(:all) do |
252 | | - @temp_puppet.unlink |
253 | | - end |
| 251 | + after(:all) do |
| 252 | + @temp_puppet.unlink |
| 253 | + end |
254 | 254 |
|
255 | | - after(:each) do |
256 | | - ENV.delete('FAKE_PUPPET_VERSION') |
| 255 | + it 'should return a puppet version upon success' do |
| 256 | + opts = { |
| 257 | + basedir: '/', |
| 258 | + node: 'foonode', |
| 259 | + puppet_binary: @temp_puppet.path, |
| 260 | + puppet_command: @temp_puppet.path, |
| 261 | + fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
| 262 | + branch: '.' |
| 263 | + } |
| 264 | + catalog = OctocatalogDiff::Catalog::Computed.new(opts) |
| 265 | + catalog.build |
| 266 | + expect(catalog.puppet_version).to eq('3.8.7') |
| 267 | + end |
257 | 268 | end |
258 | 269 |
|
259 | | - it 'should return a puppet version upon success' do |
260 | | - ENV['FAKE_PUPPET_VERSION'] = '3.8.7' |
261 | | - opts = { |
262 | | - basedir: '/', |
263 | | - node: 'foonode', |
264 | | - pass_env_vars: ['FAKE_PUPPET_VERSION'], |
265 | | - puppet_binary: @temp_puppet.path, |
266 | | - puppet_command: @temp_puppet.path, |
267 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
268 | | - branch: '.' |
269 | | - } |
270 | | - catalog = OctocatalogDiff::Catalog::Computed.new(opts) |
271 | | - catalog.build |
272 | | - expect(catalog.puppet_version).to eq('3.8.7') |
273 | | - end |
| 270 | + context 'with failing Puppet version' do |
| 271 | + before(:all) do |
| 272 | + @temp_puppet = Tempfile.new('puppet') |
| 273 | + @temp_puppet.write "#!/bin/bash\n" |
| 274 | + @temp_puppet.write "echo 1>&2 'something failed horribly'\n" |
| 275 | + @temp_puppet.write "exit 1\n" |
| 276 | + @temp_puppet.close |
| 277 | + FileUtils.chmod 0o755, @temp_puppet.path |
| 278 | + end |
274 | 279 |
|
275 | | - it 'should raise an error if the version number is empty' do |
276 | | - opts = { |
277 | | - basedir: '/', |
278 | | - node: 'foonode', |
279 | | - puppet_binary: @temp_puppet.path, |
280 | | - puppet_command: @temp_puppet.path, |
281 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
282 | | - branch: '.' |
283 | | - } |
284 | | - expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
285 | | - .to raise_error(RuntimeError, /Unable to determine Puppet version/) |
286 | | - end |
| 280 | + after(:all) do |
| 281 | + @temp_puppet.unlink |
| 282 | + end |
287 | 283 |
|
288 | | - it 'should raise an error if the puppet binary is nil' do |
289 | | - opts = { |
290 | | - basedir: '/', |
291 | | - node: 'foonode', |
292 | | - puppet_command: @temp_puppet.path, |
293 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
294 | | - branch: '.' |
295 | | - } |
296 | | - expect { OctocatalogDiff::Catalog::Computed.new(opts).build }.to raise_error(ArgumentError) |
| 284 | + it 'should raise an error if the version number is empty' do |
| 285 | + opts = { |
| 286 | + basedir: '/', |
| 287 | + node: 'foonode', |
| 288 | + puppet_binary: @temp_puppet.path, |
| 289 | + puppet_command: @temp_puppet.path, |
| 290 | + fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
| 291 | + branch: '.' |
| 292 | + } |
| 293 | + expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
| 294 | + .to raise_error(RuntimeError, /Unable to determine Puppet version/) |
| 295 | + end |
297 | 296 | end |
| 297 | + end |
298 | 298 |
|
299 | | - it 'should raise an error if the puppet binary does not exist' do |
300 | | - ENV['FAKE_PUPPET_VERSION'] = 'chicken' |
301 | | - opts = { |
302 | | - basedir: '/', |
303 | | - node: 'foonode', |
304 | | - pass_env_vars: ['FAKE_PUPPET_VERSION'], |
305 | | - puppet_binary: '/alsdfklafjasfkljafjafkjsdflaksfjasdfjadsfjadsf', |
306 | | - puppet_command: @temp_puppet.path, |
307 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
308 | | - branch: '.' |
309 | | - } |
310 | | - expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
311 | | - .to raise_error(Errno::ENOENT) |
312 | | - end |
| 299 | + it 'should raise an error if the puppet binary is nil' do |
| 300 | + opts = { |
| 301 | + basedir: '/', |
| 302 | + node: 'foonode', |
| 303 | + puppet_command: '/alsdfklafjasfkljafjafkjsdflaksfjasdfjadsfjadsf', |
| 304 | + fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
| 305 | + branch: '.' |
| 306 | + } |
| 307 | + expect { OctocatalogDiff::Catalog::Computed.new(opts).build }.to raise_error(ArgumentError) |
| 308 | + end |
313 | 309 |
|
314 | | - it 'should raise an error if the puppet binary returns a nonzero exit code' do |
315 | | - ENV['FAKE_PUPPET_VERSION'] = 'oops' |
316 | | - opts = { |
317 | | - basedir: '/', |
318 | | - node: 'foonode', |
319 | | - pass_env_vars: ['FAKE_PUPPET_VERSION'], |
320 | | - puppet_binary: @temp_puppet.path, |
321 | | - puppet_command: @temp_puppet.path, |
322 | | - fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
323 | | - branch: '.' |
324 | | - } |
325 | | - expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
326 | | - .to raise_error(RuntimeError, /Unable to determine Puppet version/) |
327 | | - end |
| 310 | + it 'should raise an error if the puppet binary does not exist' do |
| 311 | + opts = { |
| 312 | + basedir: '/', |
| 313 | + node: 'foonode', |
| 314 | + puppet_binary: '/alsdfklafjasfkljafjafkjsdflaksfjasdfjadsfjadsf', |
| 315 | + puppet_command: '/alsdfklafjasfkljafjafkjsdflaksfjasdfjadsfjadsf', |
| 316 | + fact_file: OctocatalogDiff::Spec.fixture_path('facts/valid-facts.yaml'), |
| 317 | + branch: '.' |
| 318 | + } |
| 319 | + expect { OctocatalogDiff::Catalog::Computed.new(opts).build } |
| 320 | + .to raise_error(Errno::ENOENT) |
328 | 321 | end |
329 | 322 | end |
330 | 323 |
|
|
0 commit comments