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

Handle exit status from the CLI class #310

Merged
merged 5 commits into from
Mar 11, 2020
Merged

Handle exit status from the CLI class #310

merged 5 commits into from
Mar 11, 2020

Conversation

orien
Copy link
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:

@@ -10,8 +10,7 @@ end
trap("SIGINT") { raise StackMaster::CtrlC }

begin
result = StackMaster::CLI.new(ARGV.dup).execute!
exit !!result
StackMaster::CLI.new(ARGV.dup).execute!
Copy link
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.

@@ -253,7 +253,7 @@ def execute_stacks_command(command, args, options)
end
end
end
success
@kernel.exit false unless success
Copy link
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.

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

@@ -123,6 +123,7 @@ Feature: Apply command
| + "Vpc": { |
| Parameters diff: |
| KeyName: my-key |
And the exit status should be 0
Copy link
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.

@@ -43,7 +43,7 @@ Feature: Apply command with allowed accounts
And I run `stack_master apply us-east-1 myapp-db`
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
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
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