Skip to content

Commit

Permalink
Add test for multiple checks failing
Browse files Browse the repository at this point in the history
Also sort the check keys to make sure they are in consistent order
  • Loading branch information
cornet authored and bl-robinson committed Mar 26, 2024
1 parent 39baac9 commit f566a89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/deployment/events/lambda_function_failed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(event)

def error
if preflight_checks_failed?
"The following pre-flight checks have failed: #{preflight_checks_failed.join(',')}. "\
"The following pre-flight checks have failed: #{preflight_checks_failed.join(', ')}. "\
'See https://www.notion.so/freeagent/Deployment-Playbooks-aa0f91db24954b328ebfc7d87963a185#3193a48ea76e46b29a38027150612b0d'
else
@error_message
Expand All @@ -22,7 +22,7 @@ def preflight_checks_failed?
end

def preflight_checks_failed
preflight_checks_output.select { |_k, v| v == 'FAILED' }.keys
preflight_checks_output.select { |_k, v| v == 'FAILED' }.keys.sort
end

def preflight_checks_output
Expand Down
8 changes: 4 additions & 4 deletions spec/lambda_function_failed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
RSpec.describe Deployment::Events::LambdaFunctionFailed do
subject(:deployment) { Deployment::Events::LambdaFunctionFailed.new(event) }

context 'forward deploy pre-flight check failed' do
context 'one pre flight check failed' do
let(:event) do
Aws::States::Types::HistoryEvent.new(
type: 'LambdaFunctionFailed',
Expand All @@ -29,14 +29,14 @@
end
end

context 'some other pre-flight check failed' do
context 'multiple pre flight checks failed' do
let(:event) do
Aws::States::Types::HistoryEvent.new(
type: 'LambdaFunctionFailed',
lambda_function_failed_event_details: Aws::States::Types::LambdaFunctionFailedEventDetails.new(
cause: '
{
"errorMessage": "Pre flight checks failed:\n{\"Checks\"=>{:RequiredParameters=>\"FAILED\", :CommitCheck=>\"PASSED\", :ScheduleCheck=>\"PASSED\", :ForwardDeployCheck=>\"PASSED\"}, \"Status\"=>\"FAILED\"}",
"errorMessage": "Pre flight checks failed:\n{\"Checks\"=>{:RequiredParameters=>\"FAILED\", :CommitCheck=>\"FAILED\", :ScheduleCheck=>\"FAILED\", :ForwardDeployCheck=>\"PASSED\"}, \"Status\"=>\"FAILED\"}",
"errorType": "Function<StandardError>",
"stackTrace": [
"/var/task/pre_flight_checks.rb:145:in `handler"
Expand All @@ -48,7 +48,7 @@

describe(:error) do
it 'returns full preflight failure details' do
expect(deployment.error).to start_with('The following pre-flight checks have failed: RequiredParameters.')
expect(deployment.error).to start_with('The following pre-flight checks have failed: CommitCheck, RequiredParameters, ScheduleCheck.')
end
end
end
Expand Down

0 comments on commit f566a89

Please sign in to comment.