Skip to content

Instantly share code, notes, and snippets.

@kpaulisse
Created February 26, 2017 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpaulisse/7bda51e395aab49585aa9933d78fe724 to your computer and use it in GitHub Desktop.
Save kpaulisse/7bda51e395aab49585aa9933d78fe724 to your computer and use it in GitHub Desktop.
diff --git a/lib/octocatalog-diff/catalog/computed.rb b/lib/octocatalog-diff/catalog/computed.rb
index 2f25601..5243ebb 100644
--- a/lib/octocatalog-diff/catalog/computed.rb
+++ b/lib/octocatalog-diff/catalog/computed.rb
@@ -80,7 +80,7 @@ module OctocatalogDiff
# Environment used to compile catalog
def environment
- @opts[:preserve_environments] ? @opts.fetch(:environment, 'production') : 'production'
+ @opts.fetch(:environment, 'production')
end
private
diff --git a/spec/octocatalog-diff/integration/preserve_environments_spec.rb b/spec/octocatalog-diff/integration/preserve_environments_spec.rb
index 38ebc10..db07b4d 100644
--- a/spec/octocatalog-diff/integration/preserve_environments_spec.rb
+++ b/spec/octocatalog-diff/integration/preserve_environments_spec.rb
@@ -40,20 +40,16 @@ describe 'preserve environments integration' do
'-n', 'rspec-node.github.net',
'--environment', 'asdfgh',
'--to-catalog', OctocatalogDiff::Spec.fixture_path('catalogs/default-catalog-v4.json'),
- '--hiera-config', 'environments/production/config/hiera.yaml',
+ '--hiera-config', 'config/hiera.yaml',
'--hiera-path-strip', '/var/lib/puppet', '--no-parallel'
]
)
end
it 'should exit without error' do
- expect(@result.exitcode).to eq(0), OctocatalogDiff::Integration.format_exception(@result)
+ expect(@result.exitcode).to eq(2), OctocatalogDiff::Integration.format_exception(@result)
expect(@result.exception).to be_nil, OctocatalogDiff::Integration.format_exception(@result)
end
-
- it 'should log warning about --environment being useless in this context' do
- expect(@result.logs).to match(/WARN -- : --environment is ignored unless --preserve-environments is used/)
- end
end
context 'with --create-symlinks set' do
diff --git a/spec/octocatalog-diff/tests/catalog/computed_spec.rb b/spec/octocatalog-diff/tests/catalog/computed_spec.rb
index 42e9b9b..4acca46 100644
--- a/spec/octocatalog-diff/tests/catalog/computed_spec.rb
+++ b/spec/octocatalog-diff/tests/catalog/computed_spec.rb
@@ -422,17 +422,19 @@ describe OctocatalogDiff::Catalog::Computed do
context 'when preserve_environments is not set' do
context 'and environment is specified' do
it 'should return without raising error when directory exists' do
- allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true)
+ allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false)
+ allow(File).to receive(:"directory?").with('/tmp/assert/environments/custom').and_return(true)
described_object = described_class.allocate
- described_object.instance_variable_set('@opts', environment: 'nope')
+ described_object.instance_variable_set('@opts', environment: 'custom')
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.not_to raise_error
end
it 'should raise Errno::ENOENT when directory does not exist' do
- allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(false)
+ allow(File).to receive(:"directory?").with('/tmp/assert/environments/production').and_return(true)
+ allow(File).to receive(:"directory?").with('/tmp/assert/environments/custom').and_return(false)
described_object = described_class.allocate
- described_object.instance_variable_set('@opts', environment: 'yup')
+ described_object.instance_variable_set('@opts', environment: 'custom')
described_object.instance_variable_set('@builddir', OpenStruct.new(tempdir: '/tmp/assert'))
expect { described_object.send(:assert_that_puppet_environment_directory_exists) }.to raise_error(Errno::ENOENT)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment