-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoverlay.sh
More file actions
executable file
·121 lines (105 loc) · 2.99 KB
/
Copy pathoverlay.sh
File metadata and controls
executable file
·121 lines (105 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# Internal Go overlay runner. Contributors should use ./test.
#
# Usage:
# ./overlay.sh /path/to/core [-- go test args...]
#
# This script creates a temporary directory, copies the main core repo
# and overlays test files on top, then runs `go test` there. The main
# repo is never modified.
#
# Examples:
# ./overlay.sh ../core
# ./overlay.sh ../core -- -run TestSpecific -v
# ./overlay.sh ../core -- -tags=test -count=1 ./internal/handlers/...
set -euo pipefail
if [ -z "${1:-}" ] || [ "$1" = "--" ]; then
echo "Usage: ./overlay.sh /path/to/core [-- go test args...]"
echo ""
echo "Runs tests in an isolated temp directory. The main repo is never modified."
echo ""
echo "Examples:"
echo " ./overlay.sh ../core"
echo " ./overlay.sh ../core -- -run TestSpecific -v"
echo " ./overlay.sh ../core -- -tags=test -count=1 ./internal/handlers/..."
exit 1
fi
CORE_DIR="$(cd "$1" && pwd)"
shift
if [ ! -f "$CORE_DIR/go.mod" ]; then
echo "Error: $CORE_DIR does not appear to be the core repo (no go.mod found)"
exit 1
fi
# Consume the optional "--" separator
if [ "${1:-}" = "--" ]; then
shift
fi
# Default test args if none provided. Scope is the test-bearing packages:
# ./internal/... + ./tests/... . Explicit CI invocations use ./..., so the
# overlay retains the built frontend/dist required by main.go's go:embed.
if [ $# -eq 0 ]; then
# Run internal and full-server packages separately. Integration packages
# boot a full server per test and need a larger timeout.
# 25m: ./tests boots a full server per test; fracindex stress alone ~10m.
INTERNAL_ARGS=(-tags=test -timeout=25m ./internal/...)
INTEGRATION_ARGS=(-tags=test -timeout=25m ./tests/...)
RUN_DEFAULT_SUITE=1
else
TEST_ARGS=("$@")
RUN_DEFAULT_SUITE=0
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WORK_DIR=$(mktemp -d "${TMPDIR:-/tmp}/core-test-XXXXX")
cleanup() {
rm -rf "$WORK_DIR"
}
trap cleanup EXIT
echo "==> Creating test workspace in $WORK_DIR"
# Copy main repo (exclude .git and build artifacts)
rsync -a \
--exclude='.git' \
--exclude='bin/' \
--exclude='/dist/' \
--exclude='*.db' \
--exclude='*.db-shm' \
--exclude='*.db-wal' \
--exclude='coverage.out' \
--exclude='windshift' \
--exclude='ethereal' \
--exclude='.DS_Store' \
--exclude='node_modules/' \
--exclude='/data/' \
--exclude='releases/' \
"$CORE_DIR/" "$WORK_DIR/"
# Overlay test files on top
rsync -a \
--exclude='.git' \
--exclude='overlay.sh' \
--exclude='README.md' \
--exclude='.github' \
"$SCRIPT_DIR/" "$WORK_DIR/"
echo "==> Running tests"
cd "$WORK_DIR"
set +e
EXIT_CODE=0
if [ "$RUN_DEFAULT_SUITE" -eq 1 ]; then
go test "${INTERNAL_ARGS[@]}"
if [ $? -ne 0 ]; then
EXIT_CODE=1
fi
go test "${INTEGRATION_ARGS[@]}"
if [ $? -ne 0 ]; then
EXIT_CODE=1
fi
else
go test "${TEST_ARGS[@]}"
EXIT_CODE=$?
fi
set -e
if [ $EXIT_CODE -eq 0 ]; then
echo "==> Tests passed"
else
echo "==> Tests failed (exit code $EXIT_CODE)"
fi
echo "==> Cleaning up $WORK_DIR"
exit $EXIT_CODE