| 
									
										
										
										
											2023-06-29 16:13:41 -07:00
										 |  |  | #!/usr/bin/env bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Description: Validate that the number of files in the output directory is as expected. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Arguments: | 
					
						
							|  |  |  | #   - $1: The expected number of files in the output directory. | 
					
						
							|  |  |  | #   - $2: Name of the output folder. This is used to determine the output directory and the expected output directory paths. | 
					
						
							|  |  |  | #   - $3: The expected size of the output directory in bytes (e.g. "10k"). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | set +e | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EXPECTED_NUM_FILES=$1 | 
					
						
							|  |  |  | OUTPUT_FOLDER_NAME=$2 | 
					
						
							|  |  |  | EXPECTED_SIZE=$3 | 
					
						
							|  |  |  | SCRIPT_DIR=$(dirname "$(realpath "$0")") | 
					
						
							| 
									
										
										
										
											2023-11-13 12:42:19 -06:00
										 |  |  | OUTPUT_ROOT=${OUTPUT_ROOT:-$SCRIPT_DIR} | 
					
						
							|  |  |  | EXPECTED_OUTPUT_DIR=$OUTPUT_ROOT/expected-structured-output/$OUTPUT_FOLDER_NAME | 
					
						
							| 
									
										
										
										
											2023-06-29 16:13:41 -07:00
										 |  |  | NUM_FILES=$(find "$EXPECTED_OUTPUT_DIR" -type f -size +"$EXPECTED_SIZE" | wc -l) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-28 19:04:59 -07:00
										 |  |  | # Note: single brackets and "-ne" operator were necessary for evaluation in CI | 
					
						
							|  |  |  | if [ "$NUM_FILES" -ne "$EXPECTED_NUM_FILES" ] && [ "$OVERWRITE_FIXTURES" != "true" ]; then | 
					
						
							| 
									
										
										
										
											2023-12-18 23:48:21 -08:00
										 |  |  |   echo "The test fixtures in $EXPECTED_OUTPUT_DIR look suspicious." | 
					
						
							|  |  |  |   echo "Expected $EXPECTED_NUM_FILES files, but found $NUM_FILES files found." | 
					
						
							|  |  |  |   echo "Did you overwrite test fixtures with bad outputs?" | 
					
						
							|  |  |  |   exit 1 | 
					
						
							| 
									
										
										
										
											2023-06-29 16:13:41 -07:00
										 |  |  | fi |