| 
									
										
										
										
											2023-06-29 16:13:41 -07:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Description: Compare the structured output files to the expected output files and exit with an error | 
					
						
							| 
									
										
										
										
											2023-09-21 14:51:08 -04:00
										 |  |  | #              if they are different. If the environment variable OVERWRITE_FIXTURES is not "false", | 
					
						
							| 
									
										
										
										
											2023-06-29 16:13:41 -07:00
										 |  |  | #              then this script will instead copy the output files to the expected output directory. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Arguments: | 
					
						
							|  |  |  | #   - $1: Name of the output folder. This is used to determine the output directory and the expected output directory paths. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Environment Variables: | 
					
						
							|  |  |  | #   - OVERWRITE_FIXTURES: Controls whether to overwrite fixtures or not. default: "false" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set +e | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SCRIPT_DIR=$(dirname "$(realpath "$0")") | 
					
						
							|  |  |  | OVERWRITE_FIXTURES=${OVERWRITE_FIXTURES:-false} | 
					
						
							| 
									
										
										
										
											2023-09-21 14:51:08 -04:00
										 |  |  | TMP_DIRECTORY_CLEANUP=${TMP_DIRECTORY_CLEANUP:-true} | 
					
						
							| 
									
										
										
										
											2023-06-29 16:13:41 -07:00
										 |  |  | OUTPUT_FOLDER_NAME=$1 | 
					
						
							| 
									
										
										
										
											2023-11-13 12:42:19 -06:00
										 |  |  | OUTPUT_ROOT=${OUTPUT_ROOT:-$SCRIPT_DIR} | 
					
						
							|  |  |  | OUTPUT_DIR=$OUTPUT_ROOT/structured-output/$OUTPUT_FOLDER_NAME | 
					
						
							|  |  |  | OUTPUT_DIR_TEXT=$OUTPUT_ROOT/text-output/$OUTPUT_FOLDER_NAME | 
					
						
							|  |  |  | EXPECTED_OUTPUT_DIR=$OUTPUT_ROOT/expected-structured-output/$OUTPUT_FOLDER_NAME | 
					
						
							|  |  |  | EXPECTED_OUTPUT_DIR_TEXT=$OUTPUT_ROOT/expected-text-output/$OUTPUT_FOLDER_NAME | 
					
						
							| 
									
										
										
										
											2023-06-29 16:13:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-21 14:51:08 -04:00
										 |  |  | # shellcheck disable=SC1091 | 
					
						
							|  |  |  | source "$SCRIPT_DIR"/cleanup.sh | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function cleanup() { | 
					
						
							| 
									
										
										
										
											2023-12-18 23:48:21 -08:00
										 |  |  |   if [ "$TMP_DIRECTORY_CLEANUP" == "true" ]; then | 
					
						
							|  |  |  |     cleanup_dir "$EXPECTED_OUTPUT_DIR_TEXT" | 
					
						
							|  |  |  |     cleanup_dir "$OUTPUT_DIR_TEXT" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     echo "skipping tmp directory cleanup" | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2023-09-21 14:51:08 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | trap cleanup EXIT | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-29 16:13:41 -07:00
										 |  |  | # to update ingest test fixtures, run scripts/ingest-test-fixtures-update.sh on x86_64 | 
					
						
							|  |  |  | if [ "$OVERWRITE_FIXTURES" != "false" ]; then | 
					
						
							| 
									
										
										
										
											2023-12-18 23:48:21 -08:00
										 |  |  |   # remove folder if it exists | 
					
						
							|  |  |  |   if [ -d "$EXPECTED_OUTPUT_DIR" ]; then | 
					
						
							|  |  |  |     rm -rf "$EXPECTED_OUTPUT_DIR" | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  |   mkdir -p "$EXPECTED_OUTPUT_DIR" | 
					
						
							|  |  |  |   cp -rf "$OUTPUT_DIR" "$OUTPUT_ROOT/expected-structured-output" | 
					
						
							| 
									
										
										
										
											2023-12-11 20:04:15 -05:00
										 |  |  | elif ! diff -ru "$EXPECTED_OUTPUT_DIR" "$OUTPUT_DIR"; then | 
					
						
							| 
									
										
										
										
											2023-12-18 23:48:21 -08:00
										 |  |  |   "$SCRIPT_DIR"/json-to-clean-text-folder.sh "$EXPECTED_OUTPUT_DIR" "$EXPECTED_OUTPUT_DIR_TEXT" | 
					
						
							|  |  |  |   "$SCRIPT_DIR"/json-to-clean-text-folder.sh "$OUTPUT_DIR" "$OUTPUT_DIR_TEXT" | 
					
						
							|  |  |  |   "$SCRIPT_DIR"/clean-permissions-files.sh "$OUTPUT_DIR_TEXT" | 
					
						
							|  |  |  |   diff -ru "$EXPECTED_OUTPUT_DIR_TEXT" "$OUTPUT_DIR_TEXT" >outputdiff.txt | 
					
						
							|  |  |  |   cat outputdiff.txt | 
					
						
							|  |  |  |   diffstat -c outputdiff.txt | 
					
						
							|  |  |  |   echo | 
					
						
							|  |  |  |   echo "There are differences from the previously checked-in structured outputs." | 
					
						
							|  |  |  |   echo | 
					
						
							|  |  |  |   echo "If these differences are acceptable, overwrite by the fixtures by setting the env var:" | 
					
						
							|  |  |  |   echo | 
					
						
							|  |  |  |   echo "  export OVERWRITE_FIXTURES=true" | 
					
						
							|  |  |  |   echo | 
					
						
							|  |  |  |   echo "and then rerun this script." | 
					
						
							|  |  |  |   echo | 
					
						
							|  |  |  |   echo "NOTE: You'll likely just want to run scripts/ingest-test-fixtures-update.sh on x86_64 hardware" | 
					
						
							|  |  |  |   echo "to update fixtures for CI." | 
					
						
							|  |  |  |   echo | 
					
						
							|  |  |  |   exit 1 | 
					
						
							| 
									
										
										
										
											2023-06-29 16:13:41 -07:00
										 |  |  | fi |