Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ The format is based on [Keep a Changelog], and this project adheres to

## [Unreleased]

### Changed

- Exit status is now managed by the `StackMaster::CLI` class rather than the
`stack_master` binstub ([#310]). The Cucumber test suite can now accurately
validate the exit status of each command line invocation.

### Fixed

- `stack_master --version` now returns an exit status `0` ([#310]).

[Unreleased]: https://github.com/envato/stack_master/compare/v2.1.0...HEAD
[#310]: https://github.com/envato/stack_master/pull/310

## [2.1.0] - 2020-03-06

Expand Down
3 changes: 1 addition & 2 deletions bin/stack_master
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.

rescue StackMaster::CtrlC
StackMaster.stdout.puts "Exiting..."
end
3 changes: 3 additions & 0 deletions features/apply.feature
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Feature: Apply command
| + "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.


Scenario: Run apply nothing and create 2 stacks
Given I stub the following stack events:
Expand All @@ -147,6 +148,7 @@ Feature: Apply command
Scenario: Run apply with invalid stack
When I run `stack_master apply foo bar`
Then the output should contain "Could not find stack definition bar in region foo"
And the exit status should be 1

Scenario: Create stack with --changed
Given I stub the following stack events:
Expand All @@ -161,6 +163,7 @@ Feature: Apply command
| + "Vpc": { |
| Parameters diff: |
| KeyName: my-key |
And the exit status should be 0

Scenario: Run apply with 2 specific stacks and create 2 stacks
Given I stub the following stack events:
Expand Down
2 changes: 1 addition & 1 deletion features/apply_with_allowed_accounts.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.


Scenario: Run apply with stack overriding allowed accounts to allow all accounts
Given I stub the following stack events:
Expand Down
2 changes: 2 additions & 0 deletions features/apply_with_sparkle_pack_template.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Feature: Apply command with compile time parameters
When I run `stack_master apply us-east-1 sparkle_pack_test -q --trace`
Then the output should contain all of these lines:
| Template "template_unknown" not found in any sparkle pack |
And the exit status should be 1

Scenario: An unknown compiler
Given a file named "stack_master.yml" with:
Expand All @@ -56,3 +57,4 @@ Feature: Apply command with compile time parameters
When I run `stack_master apply us-east-1 sparkle_pack_test -q --trace`
Then the output should contain all of these lines:
| Unknown compiler "foobar" |
And the exit status should be 1
3 changes: 2 additions & 1 deletion features/events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ Feature: Events command
| 1 | 1 | myapp-vpc | TestSg | CREATE_COMPLETE | AWS::EC2::SecurityGroup | 2020-10-29 00:00:00 |
| 1 | 1 | myapp-vpc | myapp-vpc | CREATE_COMPLETE | AWS::CloudFormation::Stack | 2020-10-29 00:00:00 |
When I run `stack_master events us-east-1 myapp-vpc --trace`
And the output should match /2020-10-29 00:00:00 (\+|\-)[0-9]{4} myapp-vpc AWS::CloudFormation::Stack CREATE_COMPLETE/
Then the output should match /2020-10-29 00:00:00 (\+|\-)[0-9]{4} myapp-vpc AWS::CloudFormation::Stack CREATE_COMPLETE/
And the exit status should be 0
3 changes: 2 additions & 1 deletion features/outputs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ Feature: Outputs command
}
"""
When I run `stack_master outputs us-east-1 myapp-vpc --trace`
And the output should contain all of these lines:
Then the output should contain all of these lines:
| VpcId |
| vpc-123456 |
And the exit status should be 0

Scenario: Fails when the stack doesn't exist
When I run `stack_master outputs us-east-1 myapp-vpc --trace`
Expand Down
2 changes: 2 additions & 0 deletions features/validate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ Feature: Validate command
Given I stub CloudFormation validate calls to pass validation
And I run `stack_master validate us-east-1 stack1`
Then the output should contain "stack1: valid"
And the exit status should be 0

Scenario: Validate unsuccessfully
Given I stub CloudFormation validate calls to fail validation with message "Blah"
And I run `stack_master validate us-east-1 stack1`
Then the output should contain "stack1: invalid. Blah"
And the exit status should be 1
4 changes: 4 additions & 0 deletions features/version.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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.

4 changes: 2 additions & 2 deletions lib/stack_master/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def load_config(file)
StackMaster::Config.load!(stack_file)
rescue Errno::ENOENT => e
say "Failed to load config file #{stack_file}"
exit 1
@kernel.exit false
end

def execute_stacks_command(command, args, options)
Expand All @@ -253,7 +253,7 @@ def execute_stacks_command(command, args, options)
end
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.

end

def execute_if_allowed_account(allowed_accounts, &block)
Expand Down