forked from continuwuation/continuwuity
98 lines
3.9 KiB
Bash
Executable file
98 lines
3.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
# The root path where complement is available.
|
|
COMPLEMENT_SRC="${COMPLEMENT_SRC:-$1}"
|
|
|
|
# A `.jsonl` file to write test logs to
|
|
LOG_FILE="${2:-${LOG_FILE:-complement_test_logs.jsonl}}"
|
|
|
|
# A `.jsonl` file to write test results to
|
|
RESULTS_FILE="${3:-${RESULTS_FILE:-complement_test_results.jsonl}}"
|
|
|
|
# The base docker image to use for complement tests
|
|
# You can build the default with `docker build -t continuwuity:complement -f ./docker/complement.Dockerfile .`
|
|
# after running `cargo build`. Only the debug binary is used.
|
|
COMPLEMENT_BASE_IMAGE="${COMPLEMENT_BASE_IMAGE:-continuwuity:complement}"
|
|
|
|
# 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='TestPartialStateJoin.*|TestRoomDeleteAlias/Parallel/Regular_users_can_add_and_delete_aliases_when_m.*|TestRoomDeleteAlias/Parallel/Can_delete_canonical_alias|TestUnbanViaInvite.*|TestRoomState/Parallel/GET_/publicRooms_lists.*|TestRoomDeleteAlias/Parallel/Users_with_sufficient_power-level_can_delete_other.*'
|
|
|
|
# A regex for tests to run.
|
|
RUN_TESTS="${COMPLEMENT_RUN:-.}"
|
|
|
|
# Ensure paths are absolute so they don't break when we change directory
|
|
COMPLEMENT_SRC="$(realpath -m "$COMPLEMENT_SRC")"
|
|
LOG_FILE="$(realpath -m "$LOG_FILE")"
|
|
RESULTS_FILE="$(realpath -m "$RESULTS_FILE")"
|
|
|
|
# $COMPLEMENT_SRC needs to be a directory to Complement source code
|
|
if [ ! -d "$COMPLEMENT_SRC" ]; then
|
|
echo "\$COMPLEMENT_SRC must be a directory/path to Complement source code"
|
|
exit 1
|
|
fi
|
|
|
|
toplevel="$(git rev-parse --show-toplevel)"
|
|
pushd "$toplevel" > /dev/null
|
|
|
|
|
|
# Ensure result files exist even if tests fail to start
|
|
touch "$LOG_FILE"
|
|
touch "$RESULTS_FILE"
|
|
|
|
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 "\$RUN_TESTS: $RUN_TESTS"
|
|
echo ""
|
|
|
|
# Determine the test runner and output handling
|
|
HAS_GOTESTSUM=false
|
|
command -v gotestsum >/dev/null 2>&1 && HAS_GOTESTSUM=true
|
|
echo "gotestsum installed: $HAS_GOTESTSUM"
|
|
|
|
# It's okay (likely, even) that `go test` exits nonzero
|
|
# `COMPLEMENT_ENABLE_DIRTY_RUNS=1` reuses the same complement container for faster complement, at the possible expense of test environment pollution
|
|
set +o pipefail
|
|
if [ "$HAS_GOTESTSUM" = true ]; then
|
|
# gotestsum writes full JSON logs
|
|
# We ignore the exit code because we post-process the logs even on failure.
|
|
(env \
|
|
-C "$COMPLEMENT_SRC" \
|
|
COMPLEMENT_BASE_IMAGE="$COMPLEMENT_BASE_IMAGE" \
|
|
gotestsum --format pkgname --hide-summary=output \
|
|
--jsonfile "$LOG_FILE" \
|
|
-- -tags="conduwuit_blacklist" -skip="$SKIPPED_COMPLEMENT_TESTS" -run "$RUN_TESTS" -timeout 1h ./tests/... || true)
|
|
else
|
|
# We ignore the exit code because we post-process the logs even on failure.
|
|
(env \
|
|
-C "$COMPLEMENT_SRC" \
|
|
COMPLEMENT_BASE_IMAGE="$COMPLEMENT_BASE_IMAGE" \
|
|
go test -json -tags="conduwuit_blacklist" -skip="$SKIPPED_COMPLEMENT_TESTS" -run "$RUN_TESTS" -timeout 1h ./tests/... | tee "$LOG_FILE" || true)
|
|
fi
|
|
|
|
# Post-process the results into an easy-to-compare format, sorted by Test name for reproducible results
|
|
# This ensures we have a consistent results file for the CI parser.
|
|
if [ -f "$LOG_FILE" ] && [ -s "$LOG_FILE" ]; then
|
|
jq -s -c 'sort_by(.Test)[]' < "$LOG_FILE" | jq -c '
|
|
select(
|
|
(.Action == "pass" or .Action == "fail" or .Action == "skip")
|
|
and .Test != null
|
|
) | {Action: .Action, Test: .Test}
|
|
' > "$RESULTS_FILE"
|
|
echo "processed $(wc -l < "$RESULTS_FILE") results into $RESULTS_FILE"
|
|
else
|
|
echo "Warning: $LOG_FILE is missing or empty. No results processed."
|
|
fi
|
|
set -o pipefail
|
|
|
|
echo ""
|
|
echo ""
|
|
echo "complement logs saved at $LOG_FILE"
|
|
echo "complement results saved at $RESULTS_FILE"
|
|
echo ""
|
|
echo ""
|