Skip to content

Handle exit status from the CLI class#310

Merged
orien merged 5 commits intomasterfrom
exit-status
Mar 11, 2020
Merged

Handle exit status from the CLI class#310
orien merged 5 commits intomasterfrom
exit-status

Conversation

@orien
Copy link
Copy Markdown
Member

@orien orien commented Mar 7, 2020

Context

There are a couple of peculiar StackMaster behaviours regarding exit status.

  • stack_master --version results in a status of 1 (stack_master --version returns a failed exit code #183).
  • The exit status is set in the stack_master binstub, but the Cucumber feature suite doesn't test this. It drives StackMaster via the StackMaster::CLI class directly. This makes validating the status code impossible.

Change

I propose we move handling of the exit status into the StackMaster::CLI class. This will solve both problems:

Comment thread bin/stack_master
begin
result = StackMaster::CLI.new(ARGV.dup).execute!
exit !!result
StackMaster::CLI.new(ARGV.dup).execute!
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This binstub no longer handles the exit status.

Comment thread lib/stack_master/cli.rb
end
end
success
@kernel.exit false unless success
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The CLI class now handles the exit status.

Comment thread features/version.feature
Feature: Check the StackMaster version
Scenario: Use the --version option
When I run `stack_master --version`
Then the exit status should be 0
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Add a scenario to ensure stack_master --version results in a 0 status.

Comment thread features/apply.feature
| + "Vpc": { |
| Parameters diff: |
| KeyName: my-key |
And the exit status should be 0
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Validate the exit status in all Cucumber scenarios.

And the output should contain all of these lines:
| Account '11111111' is not an allowed account. Allowed accounts are ["22222222"].|
Then the exit status should be 0
Then the exit status should be 1
Copy link
Copy Markdown
Member Author

@orien orien Mar 7, 2020

Choose a reason for hiding this comment

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

This is an example of an incorrect Cucumber validation. This scenario was ensuring a status 0, but because it was only testing via the CLI class it missed the binstub returning 1.

Now the feature correctly checks the value returned in the command invocation.

Note: this is not a change in StackMaster behaviour.

Copy link
Copy Markdown
Contributor

@patrobinson patrobinson left a comment

Choose a reason for hiding this comment

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

💯

This is something we've had a number of regressions in before.

@orien orien requested a review from stevehodgkiss March 9, 2020 23:24
@orien orien merged commit 2052255 into master Mar 11, 2020
@orien orien deleted the exit-status branch March 11, 2020 01:45
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.

stack_master --version returns a failed exit code

2 participants