-
Notifications
You must be signed in to change notification settings - Fork 95
#85: Feature/use environment without preserve #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
87d19bd
948db9f
5b3f1ee
6c2cfd2
3f2093c
05115a9
13b3417
1237ef8
9d70936
bc0f906
afe2aa3
df5353a
ba0e21c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ def compilation_dir | |
|
|
||
| # Environment used to compile catalog | ||
| def environment | ||
| @opts[:preserve_environments] ? @opts.fetch(:environment, 'production') : 'production' | ||
| @options.fetch(:environment, 'production') | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, opts. |
||
| end | ||
|
|
||
| private | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,20 +40,16 @@ | |
| '-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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one should be reverted as per my earlier comment - change the 2 back to a 0 here. |
||
| 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,15 +121,18 @@ | |
| end | ||
| end | ||
|
|
||
| context 'with --environment' do | ||
| context 'with --create-symlinks and --environment' do | ||
| context 'with logger' do | ||
| it 'should log a warning message and install default symlink' do | ||
| logger = double('Logger') | ||
| expect(logger).to receive(:warn).with('--environment is ignored unless --preserve-environments is used') | ||
| expect(logger).to receive(:warn).with( | ||
| '--create-symlinks with --environment ignored unless --preserve-environments is used' | ||
| ) | ||
|
|
||
| @described_object.instance_variable_set( | ||
| '@options', | ||
| basedir: '/tmp/basedir', | ||
| create_symlinks: %w(foo bar), | ||
| environment: 'baz' | ||
| ) | ||
|
|
||
|
|
@@ -146,6 +149,7 @@ | |
| @described_object.instance_variable_set( | ||
| '@options', | ||
| basedir: '/tmp/basedir', | ||
| create_symlinks: %w(foo bar), | ||
| environment: 'baz' | ||
| ) | ||
|
|
||
|
|
@@ -157,6 +161,41 @@ | |
| end | ||
| end | ||
| end | ||
| context 'with --environment' do | ||
| context 'with logger' do | ||
| it 'should install a symlink to the given environment' do | ||
| logger = double('Logger') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pattern elsewhere in the tests is to actually construct a real logger using: You can then also test I realize that line 127 didn't use this pattern - must have been one I missed when I went through and tried to update all of them long, long ago... Would you mind doing it the new way? 😸 |
||
|
|
||
| @described_object.instance_variable_set( | ||
| '@options', | ||
| basedir: '/tmp/basedir', | ||
| environment: 'baz' | ||
| ) | ||
|
|
||
| expect(@described_object) | ||
| .to receive(:install_directory_symlink) | ||
| .with(logger, '/tmp/basedir', 'environments/baz') | ||
|
|
||
| expect { @described_object.send(:create_symlinks, logger) }.not_to raise_error | ||
| end | ||
| end | ||
|
|
||
| context 'without logger' do | ||
| it 'should install default symlink' do | ||
| @described_object.instance_variable_set( | ||
| '@options', | ||
| basedir: '/tmp/basedir', | ||
| environment: 'baz' | ||
| ) | ||
|
|
||
| expect(@described_object) | ||
| .to receive(:install_directory_symlink) | ||
| .with(nil, '/tmp/basedir', 'environments/baz') | ||
|
|
||
| expect { @described_object.send(:create_symlinks) }.not_to raise_error | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'without --create-symlinks or --environment' do | ||
| it 'should install directory symlink' do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there should be a protection here to block
environmentandcreate-symlinksbeing used together, as the debug output on 89 states.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into this and you're actually very close here. There is a method in https://github.com/github/octocatalog-diff/blob/master/lib/octocatalog-diff/catalog/computed.rb#L82-L84 that needs to be updated to match this change. Also some spec tests need to be updated for the new behavior.
Have a look at https://gist.github.com/kpaulisse/7bda51e395aab49585aa9933d78fe724 for what I had to do to get the tests passing. Hopefully this is a push in the right direction - I'm 👍 to the change in general.