2024-04-21 15:28:35 -07:00
#!/usr/bin/env bash
set -euo pipefail
# Path to Complement's source code
#
# The `COMPLEMENT_SRC` environment variable is set in the Nix dev shell, which
# points to a store path containing the Complement source code. It's likely you
# want to just pass that as the first argument to use it here.
2024-07-06 21:15:44 -04:00
COMPLEMENT_SRC="${COMPLEMENT_SRC:-$1}"
2024-04-21 15:28:35 -07:00
# A `.jsonl` file to write test logs to
2025-03-08 00:15:13 -05:00
LOG_FILE="${2:-complement_test_logs.jsonl}"
2024-04-21 15:28:35 -07:00
# A `.jsonl` file to write test results to
2025-03-08 00:15:13 -05:00
RESULTS_FILE="${3:-complement_test_results.jsonl}"
2024-04-21 15:28:35 -07:00
2025-03-08 15:48:23 -05:00
COMPLEMENT_BASE_IMAGE="${COMPLEMENT_BASE_IMAGE:-complement-conduwuit:main}"
2024-04-21 15:28:35 -07:00
2025-03-08 00:15:13 -05:00
# Complement tests that are skipped due to flakiness/reliability issues or we don't implement such features and won't for a long time
#SKIPPED_COMPLEMENT_TESTS='-skip=TestPartialStateJoin.*'
2024-05-21 20:59:45 -04:00
2024-07-06 21:15:44 -04:00
# $COMPLEMENT_SRC needs to be a directory to Complement source code
if [ -f "$COMPLEMENT_SRC" ]; then
echo "\$COMPLEMENT_SRC must be a directory/path to Complement source code"
exit 1
fi
# quick test to make sure we can actually write to $LOG_FILE and $RESULTS_FILE
touch $LOG_FILE && rm -v $LOG_FILE
touch $RESULTS_FILE && rm -v $RESULTS_FILE
2024-05-01 23:30:49 -04:00
toplevel="$(git rev-parse --show-toplevel)"
pushd "$toplevel" > /dev/null
2024-05-06 01:09:51 -04:00
2025-03-08 01:35:26 -05:00
if [ ! -f "complement_oci_image.tar.gz" ]; then
echo "building complement conduwuit image"
2024-05-06 01:09:51 -04:00
2025-03-08 01:35:26 -05:00
# if using macOS, use linux-complement
#bin/nix-build-and-cache just .#linux-complement
bin/nix-build-and-cache just .#complement
2025-03-10 10:32:11 -04:00
#nix build -L .#complement
2025-03-08 01:35:26 -05:00
echo "complement conduwuit image tar.gz built at \"result\""
echo "loading into docker"
docker load < result
popd > /dev/null
else
echo "skipping building a complement conduwuit image as complement_oci_image.tar.gz was already found, loading this"
docker load < complement_oci_image.tar.gz
popd > /dev/null
fi
echo ""
echo "running go test with:"
echo "\$COMPLEMENT_SRC: $COMPLEMENT_SRC"
echo "\$COMPLEMENT_BASE_IMAGE: $COMPLEMENT_BASE_IMAGE"
echo "\$RESULTS_FILE: $RESULTS_FILE"
echo "\$LOG_FILE: $LOG_FILE"
echo ""
2024-04-21 15:28:35 -07:00
# It's okay (likely, even) that `go test` exits nonzero
2025-03-08 15:48:23 -05:00
# `COMPLEMENT_ENABLE_DIRTY_RUNS=1` reuses the same complement container for faster complement, at the possible expense of test environment pollution
2024-04-21 15:28:35 -07:00
set +o pipefail
env \
-C "$COMPLEMENT_SRC" \
2025-03-08 15:48:23 -05:00
COMPLEMENT_BASE_IMAGE="$COMPLEMENT_BASE_IMAGE" \
go test -tags="conduwuit_blacklist" -timeout 1h -json ./tests/... | tee "$LOG_FILE"
2024-04-21 15:28:35 -07:00
set -o pipefail
2024-05-02 10:32:30 -04:00
# Post-process the results into an easy-to-compare format, sorted by Test name for reproducible results
cat "$LOG_FILE" | jq -s -c 'sort_by(.Test)[]' | jq -c '
2024-04-21 15:28:35 -07:00
select(
(.Action == "pass" or .Action == "fail" or .Action == "skip")
and .Test != null
) | {Action: .Action, Test: .Test}
2024-05-02 10:32:30 -04:00
' > "$RESULTS_FILE"
2025-03-08 00:15:13 -05:00
2025-03-08 18:59:51 -05:00
#if command -v gotestfmt &> /dev/null; then
# echo "using gotestfmt on $LOG_FILE"
# grep '{"Time":' "$LOG_FILE" | gotestfmt > "complement_test_logs_gotestfmt.log"
#fi
2025-03-08 00:15:13 -05:00
echo ""
echo ""
echo "complement logs saved at $LOG_FILE"
echo "complement results saved at $RESULTS_FILE"
2025-03-08 18:59:51 -05:00
#if command -v gotestfmt &> /dev/null; then
# echo "complement logs in gotestfmt pretty format outputted at complement_test_logs_gotestfmt.log (use an editor/terminal/pager that interprets ANSI colours and UTF-8 emojis)"
#fi
2025-03-08 00:15:13 -05:00
echo ""
echo ""