99set -e
1010
1111# These values need to be in sync with serverless.yml, where there needs to be a function
12- # defined for every handler-runtime combination
12+ # defined for every handler_runtime combination
1313LAMBDA_HANDLERS=(" async-metrics" " sync-metrics" " http-requests" )
1414RUNTIMES=(" python27" " python36" " python37" " python38" )
1515
4444
4545cd $integration_tests_dir
4646input_event_files=$( ls ./input_events)
47- # Sort events by name so that snapshots stay consistent
47+ # Sort event files by name so that snapshots stay consistent
4848input_event_files=($( for file_name in ${input_event_files[@]} ; do echo $file_name ; done | sort) )
4949
5050echo " Deploying functions"
5151serverless deploy
5252
5353echo " Invoking functions"
54- set +e # Don't immediately exit this script if an invocation fails or there's a diff
54+ set +e # Don't exit this script if an invocation fails or there's a diff
5555for handler_name in " ${LAMBDA_HANDLERS[@]} " ; do
5656 for runtime in " ${RUNTIMES[@]} " ; do
5757 function_name=" ${handler_name} _${runtime} "
@@ -64,10 +64,13 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
6464
6565 return_value=$( serverless invoke -f $function_name --path " ./input_events/$input_event_file " )
6666
67- if [ -n " $UPDATE_SNAPSHOTS " ] || [ ! -f $snapshot_path ]; then
68- # If $UPDATE_SNAPSHOTS is set to true, write the new logs over the current snapshot
67+ if [ ! -f $snapshot_path ]; then
6968 # If the snapshot file doesn't exist yet, we create it
70- echo " Writing return value snapshot for $snapshot_path "
69+ echo " Writing return value to $snapshot_path because no snapshot exists yet"
70+ echo " $return_value " > $snapshot_path
71+ elif [ -n " $UPDATE_SNAPSHOTS " ]; then
72+ # If $UPDATE_SNAPSHOTS is set to true, write the new logs over the current snapshot
73+ echo " Overwriting return value snapshot for $snapshot_path "
7174 echo " $return_value " > $snapshot_path
7275 else
7376 # Compare new return value to snapshot
@@ -116,10 +119,13 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
116119 sed -E " s/(api_key=|'api_key': ')[a-z0-9\.\-]+/\1XXXX/g"
117120 )
118121
119- if [ -n " $UPDATE_SNAPSHOTS " ] || [ ! -f $function_snapshot_path ]; then
122+ if [ ! -f $function_snapshot_path ]; then
123+ # If no snapshot file exists yet, we create one
124+ echo " Writing logs to $function_snapshot_path because no snapshot exists yet"
125+ echo " $logs " > $function_snapshot_path
126+ elif [ -n " $UPDATE_SNAPSHOTS " ]; then
120127 # If $UPDATE_SNAPSHOTS is set to true write the new logs over the current snapshot
121- # If no file exists yet, we create one
122- echo " Writing log snapshot for $function_name "
128+ echo " Overwriting log snapshot for $function_snapshot_path "
123129 echo " $logs " > $function_snapshot_path
124130 else
125131 # Compare new logs to snapshots
0 commit comments