Skip to content
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

#85: Feature/use environment without preserve #86

Merged

Conversation

homelinen
Copy link
Contributor

@homelinen homelinen commented Feb 23, 2017

Overview

This pull request changes the behaviour of the --environment flag when used on its own.

Solve the problem described in #85. Allows the --environment flag to be used without the --preserve-environments flag.

Tries to maintain the current functionality by ignoring this parameter when used with --create-symlinks.

Doesn't modify the existing behaviour of --preserve-environments

Checklist

  • Make sure that all of the tests pass, and fix any that don't. Just run rake in your checkout directory, or review the CI job triggered whenever you push to a pull request.
  • Make sure that there is 100% test coverage by running rake coverage:spec or ignoring untestable sections of code with # :nocov comments. If you need help getting to 100% coverage please ask; however, don't just submit code with no tests.
  • If you have added a new command line option, we would greatly appreciate a corresponding integration test that exercises it from start to finish. This is optional but recommended.
  • If you have added any new gem dependencies, make sure those gems are licensed under the MIT or Apache 2.0 license. We cannot add any dependencies on gems licensed under GPL.
  • If you have added any new gem dependencies, make sure you've checked in a copy of the .gem file into the vendor/cache directory.

@homelinen
Copy link
Contributor Author

Will try to write an integration test and test against my existing repository. (The puppet version was causing some troubles, I'll try and figure out how to make that work).

Integration tests don't work locally because I presume github.net is an internal domain so wanted to test again Travis.

@@ -330,7 +334,7 @@ def install_ssl_client_password(logger, password)
end

def environment
@options[:preserve_environments] ? @options.fetch(:environment, 'production') : 'production'
@options.fetch(:environment, 'production')
Copy link
Contributor Author

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 environment and create-symlinks being used together, as the debug output on 89 states.

Copy link
Contributor

@kpaulisse kpaulisse Feb 26, 2017

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.

@@ -142,10 +145,11 @@
end

context 'without logger' do
it 'should install default symlink' do
it 'should install directory symlink' do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still say default. Oops.

@@ -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')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, opts.

@homelinen
Copy link
Contributor Author

Will look at those failed tests over the next few days. Haven't checked them yet.

But managed to get environment working fully on my own repo so that's good progress.

@kpaulisse
Copy link
Contributor

Hey @homelinen I looked at the test results and this one looks like it might just be a broken test:

  1) preserve environments integration without --preserve-environments set with --environment set should exit without error
     Failure/Error: expect(@result.exitcode).to eq(2), OctocatalogDiff::Integration.format_exception(@result)
     
       expected: 2
            got: 0
     
       (compared using ==)
     # ./spec/octocatalog-diff/integration/preserve_environments_spec.rb:50:in `block (4 levels) in <top (required)>'
     # ./vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.5.0/lib/rspec/retry.rb:112:in `block in run'
     # ./vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.5.0/lib/rspec/retry.rb:101:in `loop'
     # ./vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.5.0/lib/rspec/retry.rb:101:in `run'
     # ./vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.5.0/lib/rspec_ext/rspec_ext.rb:12:in `run_with_retry'
     # ./vendor/bundle/ruby/2.3.0/gems/rspec-retry-0.5.0/lib/rspec/retry.rb:30:in `block (2 levels) in setup'

Basically 2 means "successful, with diffs" and 0 means "successful, no diffs". It looks like you actually changed the original test from 0 to 2 (and I vaguely remember this being in my patch when I first tried your code on my machine but I didn't look into it too deeply at the time). I just re-ran that on my machine and got the same failure as travis is seeing, so if you revert just that one change the test will hopefully pass as it did before.

Copy link
Contributor

@kpaulisse kpaulisse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad to hear this is mostly working for you. I pointed out the test that needs fixing, and made one suggestion about the logger.

Once you have verified code that works for you and let me know you're done, I'll run the updated code within GitHub for a day or so to make sure everything looks good (we end up running this up to 10k times per day in various CI) and then merge. Thanks!

'--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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

context 'with --environment' do
context 'with logger' do
it 'should install a symlink to the given environment' do
logger = double('Logger')
Copy link
Contributor

Choose a reason for hiding this comment

The 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:

logger, logger_str = OctocatalogDiff::Spec.setup_logger

You can then also test logger_str.string to be matching text if you want to verify log messages.

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? 😸

@homelinen homelinen force-pushed the feature/use_environment_without_preserve branch from 20bfdeb to ba0e21c Compare March 10, 2017 17:31
@kpaulisse
Copy link
Contributor

@homelinen the code looks fine now. Are you done with the development here? If so I'll test this internally within GitHub for a couple days, and then merge it. Please advise.

@homelinen
Copy link
Contributor Author

@kpaulisse Yeah, I'm done with the development, I'm happy for internal testing to go ahead.

I realise one thing missing is a doc change to the Advanced Environments page. Would you want that in this PR or separate?

Happy to work it out either, sorry I forgot about it before.

@kpaulisse
Copy link
Contributor

Feel free to do a separate PR for doc updates. I don't bump version numbers for that.

We are testing this version within GitHub today and if all goes well I'll merge it tomorrow. Thanks again!

@kpaulisse kpaulisse merged commit ba0e21c into github:master Mar 15, 2017
kpaulisse added a commit that referenced this pull request Mar 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants