-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·82 lines (73 loc) · 2.25 KB
/
test.sh
File metadata and controls
executable file
·82 lines (73 loc) · 2.25 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
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f /.dockerenv ] && ! grep -qE '(docker|containerd|kubepods)' /proc/1/cgroup 2>/dev/null; then
echo "RUN THESE ONLY IN DOCKER YOU FOOL" >&2
exit 1
fi
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export SHIPLOG_HOME="${SHIPLOG_HOME:-$ROOT_DIR}"
export SHIPLOG_LIB_DIR="${SHIPLOG_LIB_DIR:-$SHIPLOG_HOME/lib}"
export SHIPLOG_REF_ROOT="${SHIPLOG_REF_ROOT:-refs/_shiplog}"
export SHIPLOG_NOTES_REF="${SHIPLOG_NOTES_REF:-refs/_shiplog/notes/logs}"
export PATH="$SHIPLOG_HOME/bin:$PATH"
# Avoid network during tests by default; use local sandbox init
export SHIPLOG_USE_LOCAL_SANDBOX="${SHIPLOG_USE_LOCAL_SANDBOX:-1}"
# Enforce a timeout for the Bats test run (set TEST_TIMEOUT_SECS=0 to disable)
TEST_TIMEOUT_SECS="${TEST_TIMEOUT_SECS:-180}"
use_timeout() {
local val="$1"
case "$val" in
''|0|0s|0S|0sec|0SEC) return 1 ;;
*[!0-9]*) return 2 ;;
esac
[ "$val" -gt 0 ]
}
run_bats() {
local timeout_seconds="${1:-}"
shift || true
if [ -n "$timeout_seconds" ]; then
timeout "${timeout_seconds}s" bats "$@"
else
bats "$@"
fi
}
if ! command -v bats >/dev/null 2>&1; then
echo "bats is required to run the Shiplog test suite" >&2
exit 127
fi
timeout_enabled=0
use_timeout "$TEST_TIMEOUT_SECS"
timeout_status=$?
case "$timeout_status" in
0) timeout_enabled=1 ;;
1) timeout_enabled=0 ;;
2)
echo "shiplog test.sh: TEST_TIMEOUT_SECS must be a positive integer or 0 (got '${TEST_TIMEOUT_SECS}')" >&2
exit 64
;;
esac
if command -v timeout >/dev/null 2>&1; then
if [ "$timeout_enabled" -eq 1 ]; then
if [ -n "${BATS_FLAGS:-}" ]; then
run_bats "$TEST_TIMEOUT_SECS" $BATS_FLAGS "$SHIPLOG_HOME/test"
else
run_bats "$TEST_TIMEOUT_SECS" -r "$SHIPLOG_HOME/test"
fi
else
if [ -n "${BATS_FLAGS:-}" ]; then
run_bats "" $BATS_FLAGS "$SHIPLOG_HOME/test"
else
run_bats "" -r "$SHIPLOG_HOME/test"
fi
fi
else
if [ "$timeout_enabled" -eq 1 ]; then
echo "shiplog test.sh: timeout command not found but TEST_TIMEOUT_SECS=${TEST_TIMEOUT_SECS}; install coreutils timeout or set TEST_TIMEOUT_SECS=0" >&2
exit 64
fi
if [ -n "${BATS_FLAGS:-}" ]; then
run_bats "" $BATS_FLAGS "$SHIPLOG_HOME/test"
else
run_bats "" -r "$SHIPLOG_HOME/test"
fi
fi