unstructured/test_unstructured_ingest/check-diff-expected-output.sh
ryannikolaidis 62e20442df
chore: refactor ingest tests (#814)
- Adds reusable validation scripts (check-x.sh) to minimize repeated (or near-repeated) code and create one source of truth
- Restructures the location of download and output folders such that they are nested in the test_unstructured_ingest directory
- Adds gitignore for output folders / files to avoid them accidentally getting checked into the repository
- Construct paths as reusable variables declared at top of scripts
- Sort order of flag for ingest calls, across all tests (this makes it easier to parse at a glance)
- OVERWRITE_FIXTURES removes all old fixtures for path to guarantee no stale results are left behind
- Bonus: don't check/exit on expected number of expected outputs when OVERWRITE_FIXTURES is true
- Bonus: exclude file_directory from Slack and Discord test scripts (match convention in all others)
2023-06-29 23:13:41 +00:00

44 lines
1.7 KiB
Bash

#!/usr/bin/env bash
# Description: Compare the structured output files to the expected output files and exit with an error
# if they are different. If the environment variable OVERWRITE_FIXTURES is not "false",
# 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}
OUTPUT_FOLDER_NAME=$1
OUTPUT_DIR=$SCRIPT_DIR/structured-output/$OUTPUT_FOLDER_NAME
EXPECTED_OUTPUT_DIR=$SCRIPT_DIR/expected-structured-output/$OUTPUT_FOLDER_NAME
# to update ingest test fixtures, run scripts/ingest-test-fixtures-update.sh on x86_64
if [ "$OVERWRITE_FIXTURES" != "false" ]; then
# 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" "$SCRIPT_DIR/expected-structured-output"
elif ! diff -ru "$EXPECTED_OUTPUT_DIR" "$OUTPUT_DIR" ; then
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
fi