-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tests
More file actions
executable file
·237 lines (212 loc) · 6.64 KB
/
run-tests
File metadata and controls
executable file
·237 lines (212 loc) · 6.64 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env bash
# Smart wrapper for running integration tests (keeps backward compatibility)
# - In BACKUP_MODE=wal it can provision a local SSH key under secrets/walg_ssh_key
# so the postgres wal-g setup can proceed in the test container.
# - Adds fast/quiet flags to speed local iterations and reduce noisy output.
# - Use --offline to run only tests that don't require Docker.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEST_SCRIPT="$SCRIPT_DIR/test/run-tests.sh"
if [[ ! -f "$TEST_SCRIPT" ]]; then
echo "Error: test script not found at $TEST_SCRIPT" >&2
exit 2
fi
# Defaults (can be overridden by flags)
QUIET=${QUIET:-0}
# Default to FAST=1 for quicker local runs; use --e2e to force full
FAST=${FAST:-1} # When 1, skip heavyweight E2E flows when possible (default)
E2E=${E2E:-0} # Force running heavyweight E2E
REUSE=${REUSE:-0} # When 1, do not cleanup containers/volumes
OFFLINE=${OFFLINE:-0} # When 1, run only offline tests (no Docker required)
print() {
# print only when not in quiet mode
if [[ "$QUIET" != "1" ]]; then
echo "$@"
fi
}
usage() {
cat <<EOF
Usage: $(basename "$0") [options] [-- extra-args]
Options:
-q, --quiet Reduce output from this wrapper and child scripts
-f, --fast, --quick Faster run (skips heavy WAL-G E2E in basic mode)
Default: fast. Combine with --e2e for fast E2E.
--e2e Run WAL-G E2E (respects --fast unless --full is used)
--full Run full WAL-G E2E (disables fast mode)
--offline Run offline tests only (no Docker required)
--mode <sql|wal> Override BACKUP_MODE
--reuse Skip environment cleanup for faster re-runs
--no-cleanup Alias for --reuse
-h, --help Show this help
Environment:
BACKUP_MODE=sql|wal Default test mode (falls back to .env, then sql)
QUIET=1 Same as --quiet
FAST=1 Same as --fast
E2E=1 Same as --e2e
REUSE=1 Same as --reuse
OFFLINE=1 Same as --offline
Examples:
BACKUP_MODE=wal $0 --fast --quiet
$0 --mode sql -q --reuse
$0 --offline
EOF
}
load_env_file() {
if [[ -f "$SCRIPT_DIR/.env" ]]; then
# shellcheck disable=SC1090
set -o allexport
source "$SCRIPT_DIR/.env" >/dev/null 2>&1 || true
set +o allexport
fi
}
# Parse CLI flags (before .env loading so --offline can skip it)
PASS_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
-q|--quiet)
QUIET=1
;;
-f|--fast|--quick)
FAST=1
;;
--e2e)
E2E=1
;;
--full)
E2E=1
FAST=0
;;
--offline)
OFFLINE=1
;;
--mode)
BACKUP_MODE="${2:-}"
shift || true
;;
--mode=*)
BACKUP_MODE="${1#*=}"
;;
--reuse|--no-cleanup)
REUSE=1
;;
-h|--help)
usage
exit 0
;;
--)
shift
PASS_ARGS+=("$@")
break
;;
*)
PASS_ARGS+=("$1")
;;
esac
shift || true
done
# Determine mode from environment or .env (skip in offline mode to avoid
# exporting Docker-only vars like TZ into test subprocesses).
BACKUP_MODE="${BACKUP_MODE:-}"
if [[ "$OFFLINE" != "1" && -z "$BACKUP_MODE" ]]; then
load_env_file
BACKUP_MODE="${BACKUP_MODE:-}"
fi
# Child scripts can honor these too
export QUIET FAST E2E REUSE OFFLINE
run_offline() {
print "Running offline tests (no Docker required)..."
local failed=0
if [[ -f "$SCRIPT_DIR/test/test-regression.sh" ]]; then
print "--- Regression tests ---"
bash "$SCRIPT_DIR/test/test-regression.sh" || failed=1
fi
if [[ -f "$SCRIPT_DIR/test/test-offline-e2e.sh" ]]; then
print "--- Offline WAL-G E2E tests ---"
bash "$SCRIPT_DIR/test/test-offline-e2e.sh" || failed=1
fi
if [[ "$failed" == "1" ]]; then
echo "Some offline tests failed." >&2
exit 1
fi
print "All offline tests passed."
}
run_sql_mode() {
print "Running tests in SQL backup mode..."
local cleanup_flag
cleanup_flag=$([[ "$REUSE" == "1" ]] && echo 0 || echo 1)
BACKUP_MODE=sql CLEANUP="$cleanup_flag" "$TEST_SCRIPT" "${PASS_ARGS[@]}"
}
run_wal_mode() {
print "Running tests in WAL (wal-g) backup mode..."
# If ENABLE_SSH_SERVER=1 then setup local ssh server, else rely on existing WALG_SSH_PREFIX
ENABLE_SSH_SERVER_VAL="${ENABLE_SSH_SERVER:-}"; export ENABLE_SSH_SERVER_VAL
if [[ -z "$ENABLE_SSH_SERVER_VAL" ]]; then
load_env_file
ENABLE_SSH_SERVER_VAL="${ENABLE_SSH_SERVER:-}"; export ENABLE_SSH_SERVER_VAL
fi
if [[ "$ENABLE_SSH_SERVER_VAL" == "1" ]]; then
print "ENABLE_SSH_SERVER=1 -> provisioning internal ssh-server for tests"
"$SCRIPT_DIR/scripts/setup-local-ssh.sh"
print "Local SSH server environment prepared."
else
# Ensure WALG_SSH_PREFIX present unless internal server is requested later
if [[ -z "${WALG_SSH_PREFIX:-}" ]]; then
load_env_file
fi
if [[ -z "${WALG_SSH_PREFIX:-}" ]]; then
echo "Error: WALG_SSH_PREFIX must be set in environment or .env for WAL mode when ENABLE_SSH_SERVER!=1" >&2
echo "Hint: run scripts/setup-local-ssh.sh or set ENABLE_SSH_SERVER=1 for an embedded test server" >&2
exit 4
fi
fi
# Choose between full E2E and faster basic run
if [[ "$FAST" == "1" && "$E2E" != "1" ]]; then
print "Fast mode: running basic WAL-G tests (skip heavy E2E). Use --e2e for full run."
FORCE_EMPTY_PGDATA=1 SKIP_SSH_KEYSCAN=1 BACKUP_MODE=wal CLEANUP=$([[ "$REUSE" == "1" ]] && echo 0 || echo 1) \
"$TEST_SCRIPT" "${PASS_ARGS[@]}"
else
print "Running comprehensive WAL-G E2E tests..."
if [[ -f "$SCRIPT_DIR/test/test-walg-e2e.sh" ]]; then
FORCE_EMPTY_PGDATA=1 CLEANUP=$([[ "$REUSE" == "1" ]] && echo 0 || echo 1) \
"$SCRIPT_DIR/test/test-walg-e2e.sh" "${PASS_ARGS[@]}"
else
print "WAL-G E2E test script not found, falling back to basic tests..."
FORCE_EMPTY_PGDATA=1 SKIP_SSH_KEYSCAN=1 BACKUP_MODE=wal CLEANUP=$([[ "$REUSE" == "1" ]] && echo 0 || echo 1) \
"$TEST_SCRIPT" "${PASS_ARGS[@]}"
fi
fi
# Clean up test environment unless reusing
if [[ "$REUSE" != "1" ]]; then
print "Cleaning up test environment..."
if [[ "$QUIET" == "1" ]]; then
docker compose --profile ssh-testing down -v >/dev/null 2>&1 || true
else
docker compose --profile ssh-testing down -v || true
fi
print "Test environment cleaned up."
else
print "Reuse enabled: keeping environment for faster subsequent runs."
fi
}
# Handle --offline mode first (no Docker, no BACKUP_MODE needed)
if [[ "$OFFLINE" == "1" ]]; then
run_offline
exit $?
fi
case "$BACKUP_MODE" in
wal|WAL|Wal)
run_wal_mode
;;
sql|SQL|Sql)
run_sql_mode
;;
"")
# Default to SQL mode for safety if not specified
print "No BACKUP_MODE detected; defaulting to SQL mode (safer)."
run_sql_mode
;;
*)
echo "Unknown BACKUP_MODE='$BACKUP_MODE' - please set BACKUP_MODE=sql or wal" >&2
exit 3
;;
esac