4242 echo " Not building layers, ensure they've already been built or re-run with 'REBUILD_LAYERS=true ./scripts/run_integration_tests.sh'"
4343fi
4444
45- echo " Deploying functions"
4645cd $integration_tests_dir
46+ input_event_files=$( ls ./input_events)
47+ # Sort events by name so that snapshots stay consistent
48+ input_event_files=($( for file_name in ${input_event_files[@]} ; do echo $file_name ; done | sort) )
49+
50+ echo " Deploying functions"
4751serverless deploy
4852
4953echo " Invoking functions"
5054set +e # Don't immediately exit this script if an invocation fails or there's a diff
5155for handler_name in " ${LAMBDA_HANDLERS[@]} " ; do
5256 for runtime in " ${RUNTIMES[@]} " ; do
5357 function_name=" ${handler_name} _${runtime} "
54- function_snapshot_path=" ./snapshots/$function_name .return_value"
55-
56- return_value=$( serverless invoke -f $function_name )
57-
58- if [ -n " $UPDATE_SNAPSHOTS " ] || [ ! -f $function_snapshot_path ]; then
59- # If $UPDATE_SNAPSHOTS is set to true, write the new logs over the current snapshot
60- # If the snapshot file doesn't exist yet, we create it
61- echo " Writing return value snapshot for $function_name "
62- echo " $return_value " > $function_snapshot_path
63- else
64- # Compare new return value to snapshot
65- diff_output=$( echo " $return_value " | diff - $function_snapshot_path )
66- if [ $? -eq 1 ]; then
67- echo " Failed: Return value for $function_name does not match snapshot:"
68- echo " $diff_output "
69- mismatch_found=true
58+ # Invoke function once for each input event
59+ for input_event_file in " ${input_event_files[@]} " ; do
60+ echo " input_event_file=$input_event_file "
61+ # Get event name without trailing ".json" so we can build the snapshot name
62+ input_event_name=$( echo " $input_event_file " | sed " s/.json//" )
63+ # Return value snapshot file format is snapshots/return_values/{handler}_{runtime}_{input-event}
64+ snapshot_path=" ./snapshots/return_values/${function_name} _${input_event_name} .json"
65+
66+ return_value=$( serverless invoke -f $function_name --path " ./input_events/$input_event_file " )
67+
68+ if [ -n " $UPDATE_SNAPSHOTS " ] || [ ! -f $snapshot_path ]; then
69+ # If $UPDATE_SNAPSHOTS is set to true, write the new logs over the current snapshot
70+ # If the snapshot file doesn't exist yet, we create it
71+ echo " Writing return value snapshot for $snapshot_path "
72+ echo " $return_value " > $snapshot_path
7073 else
71- echo " Ok: Return value for $function_name matches snapshot"
74+ # Compare new return value to snapshot
75+ diff_output=$( echo " $return_value " | diff - $snapshot_path )
76+ if [ $? -eq 1 ]; then
77+ echo " Failed: Return value for $function_name does not match snapshot:"
78+ echo " $diff_output "
79+ mismatch_found=true
80+ else
81+ echo " Ok: Return value for $function_name matches snapshot"
82+ fi
7283 fi
73- fi
84+ done
85+
7486 done
87+
7588done
7689set -e
7790
@@ -82,7 +95,7 @@ echo "Fetching logs for invocations and comparing to snapshots"
8295for handler_name in " ${LAMBDA_HANDLERS[@]} " ; do
8396 for runtime in " ${RUNTIMES[@]} " ; do
8497 function_name=" ${handler_name} _${runtime} "
85- function_snapshot_path=" ./snapshots/$function_name .logs "
98+ function_snapshot_path=" ./snapshots/logs/ $function_name .log "
8699
87100 # Fetch logs with serverless cli
88101 raw_logs=$( serverless logs -f $function_name --startTime $script_start_time )
@@ -92,6 +105,8 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
92105 echo " $raw_logs " |
93106 # Filter serverless cli errors
94107 sed ' /Serverless: Recoverable error occurred/d' |
108+ # Remove blank lines
109+ sed ' /^$/d' |
95110 # Normalize Lambda runtime report logs
96111 sed -E ' s/(RequestId|TraceId|SegmentId|Duration|Memory Used|"e"): [a-z0-9\.\-]+/\1: XXXX/g' |
97112 # Normalize DD APM headers
0 commit comments