Skip to content

Commit 40b8f2c

Browse files
author
Kevin Paulisse
committed
Add test coverage for assert_that_puppet_environment_directory_exists
1 parent b549023 commit 40b8f2c

1 file changed

Lines changed: 82 additions & 0 deletions

File tree

spec/octocatalog-diff/tests/catalog/computed_spec.rb

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'json'
4+
require 'ostruct'
45

56
require_relative '../spec_helper'
67

@@ -375,4 +376,85 @@
375376
expect { obj.send(:cleanup_checkout_dir, dir, logger) }.not_to raise_error
376377
end
377378
end
379+
380+
describe '#assert_that_puppet_environment_directory_exists' do
381+
before(:each) do
382+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/yup').and_return(true)
383+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/nope').and_return(false)
384+
end
385+
386+
context 'when preserve_environments is set' do
387+
context 'and environment is specified' do
388+
it 'should return without raising error when directory exists' do
389+
described_object = described_class.allocate
390+
described_object.instance_variable_set('@opts', preserve_environments: true, environment: 'yup')
391+
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
392+
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error
393+
end
394+
395+
it 'should raise Errno::ENOENT when directory does not exist' do
396+
described_object = described_class.allocate
397+
described_object.instance_variable_set('@opts', preserve_environments: true, environment: 'nope')
398+
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
399+
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT)
400+
end
401+
end
402+
403+
context 'and environment is not specified' do
404+
it 'should return without raising error when directory exists' do
405+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true)
406+
described_object = described_class.allocate
407+
described_object.instance_variable_set('@opts', preserve_environments: true)
408+
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
409+
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error
410+
end
411+
412+
it 'should raise Errno::ENOENT when directory does not exist' do
413+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false)
414+
described_object = described_class.allocate
415+
described_object.instance_variable_set('@opts', preserve_environments: true, environment: 'nope')
416+
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
417+
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT)
418+
end
419+
end
420+
end
421+
422+
context 'when preserve_environments is not set' do
423+
context 'and environment is specified' do
424+
it 'should return without raising error when directory exists' do
425+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true)
426+
described_object = described_class.allocate
427+
described_object.instance_variable_set('@opts', environment: 'nope')
428+
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
429+
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error
430+
end
431+
432+
it 'should raise Errno::ENOENT when directory does not exist' do
433+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false)
434+
described_object = described_class.allocate
435+
described_object.instance_variable_set('@opts', environment: 'yup')
436+
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
437+
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT)
438+
end
439+
end
440+
441+
context 'and environment is not specified' do
442+
it 'should return without raising error when directory exists' do
443+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true)
444+
described_object = described_class.allocate
445+
described_object.instance_variable_set('@opts', {})
446+
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
447+
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error
448+
end
449+
450+
it 'should raise Errno::ENOENT when directory does not exist' do
451+
allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false)
452+
described_object = described_class.allocate
453+
described_object.instance_variable_set('@opts', {})
454+
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
455+
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT)
456+
end
457+
end
458+
end
459+
end
378460
end

0 commit comments

Comments
 (0)