From f566a890a8c01ecad9df50e6c4c5311a4db4b7ad Mon Sep 17 00:00:00 2001 From: Nathan Meehan-Howard Date: Thu, 21 Mar 2024 16:45:36 +0000 Subject: [PATCH] Add test for multiple checks failing Also sort the check keys to make sure they are in consistent order --- lib/deployment/events/lambda_function_failed.rb | 4 ++-- spec/lambda_function_failed_spec.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/deployment/events/lambda_function_failed.rb b/lib/deployment/events/lambda_function_failed.rb index df810da..d806c55 100644 --- a/lib/deployment/events/lambda_function_failed.rb +++ b/lib/deployment/events/lambda_function_failed.rb @@ -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 @@ -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 diff --git a/spec/lambda_function_failed_spec.rb b/spec/lambda_function_failed_spec.rb index fa38c5e..c8f6349 100644 --- a/spec/lambda_function_failed_spec.rb +++ b/spec/lambda_function_failed_spec.rb @@ -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', @@ -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", "stackTrace": [ "/var/task/pre_flight_checks.rb:145:in `handler" @@ -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