Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·132 lines (115 loc) · 4.87 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·132 lines (115 loc) · 4.87 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
#!/bin/sh
# automated smoke test for the google-drive-ocamlfuse container
# builds the image and asserts the from-source binary + its runtime libs load.
#
# NOTE: a full Google Drive mount can't be tested headless/in CI - it needs an
# interactive OAuth flow (browser consent + credentials). so the meaningful
# functional check is running the compiled binary and confirming it executes,
# prints its version and that the fuse runtime is present. this proves the
# opam-built binary and its shared libs (fuse3, gmp, sqlite, curl, ...) load.
set -eu
IMAGE=google-drive-ocamlfuse-test
NAME=google-drive-ocamlfuse-test-run
ENTRYNAME=google-drive-ocamlfuse-test-entrypoint
FAILED=0
fail() {
echo "FAIL: $*" >&2
FAILED=1
}
cleanup() {
echo ">> cleanup: removing containers $NAME $ENTRYNAME"
docker rm -f "$NAME" >/dev/null 2>&1 || true
docker rm -f "$ENTRYNAME" >/dev/null 2>&1 || true
}
trap cleanup EXIT INT TERM
echo ">> building image $IMAGE"
docker build -t "$IMAGE" .
# start a long-lived container overriding the entrypoint (the real entrypoint
# tries to mount google drive and would exit without credentials). we keep it
# idle and poke it with docker exec - no host bind-mounts.
echo ">> (re)starting container $NAME"
docker rm -f "$NAME" >/dev/null 2>&1 || true
docker run -d --name "$NAME" --entrypoint sh "$IMAGE" -c 'sleep 300'
echo ">> assert: container is running"
if docker ps --format '{{.Names}}' | grep -q "^${NAME}$"; then
echo "ok - container running"
else
echo "!! container is not running, dumping logs:" >&2
docker logs "$NAME" >&2 2>&1 || true
fail "container not running"
fi
if docker ps --format '{{.Names}}' | grep -q "^${NAME}$"; then
echo ">> assert: google-drive-ocamlfuse binary exists and is executable"
if docker exec "$NAME" sh -c 'command -v google-drive-ocamlfuse >/dev/null'; then
echo "ok - binary present on PATH"
else
fail "google-drive-ocamlfuse not found on PATH"
fi
echo ">> assert: 'google-drive-ocamlfuse -version' runs and prints 0.9.x"
VERSION_OUT=$(docker exec "$NAME" google-drive-ocamlfuse -version 2>&1 || true)
echo "$VERSION_OUT"
if echo "$VERSION_OUT" | grep -Eq 'google-drive-ocamlfuse, version 0\.9\.[0-9]+'; then
echo "ok - binary executed and reported version: $(echo "$VERSION_OUT" | grep -Eo 'version 0\.9\.[0-9]+')"
else
fail "binary did not report expected 0.9.x version (runtime libs may be missing)"
fi
echo ">> assert: fuse3 runtime (fusermount3) is present"
if docker exec "$NAME" sh -c 'command -v fusermount3 >/dev/null'; then
echo "ok - fusermount3 available"
else
fail "fusermount3 not found (fuse3 runtime missing)"
fi
fi
# entrypoint smoke test: run the REAL entrypoint with dummy env and no
# credentials. without auth the app must get past argument parsing and block
# waiting for the OAuth flow - it must never print its usage text. this is
# exactly the bug class where the launcher passes a flag a newer
# google-drive-ocamlfuse dropped (e.g. '-f', removed once the process always
# stays in foreground) and every container start crash-loops.
# a tmpfs on /data provides the mountpoint without host binds; /dev/fuse is
# not needed because the mount only happens after auth succeeds.
echo ">> (re)starting container $ENTRYNAME (real entrypoint, no credentials)"
docker rm -f "$ENTRYNAME" >/dev/null 2>&1 || true
docker run -d --name "$ENTRYNAME" \
--mount type=tmpfs,dst=/data \
-e ACCOUNT_smoke=1000 -e PUID=1000 -e PGID=1000 \
-e CLIENT_ID=dummy-client-id.apps.example \
-e CLIENT_SECRET=dummy-client-secret \
"$IMAGE"
echo ">> waiting 12s for the entrypoint to reach the auth/mount stage"
sleep 12
ENTRY_LOGS=$(docker logs "$ENTRYNAME" 2>&1 || true)
echo ">> assert: entrypoint does not trip over its own arguments"
if echo "$ENTRY_LOGS" | grep -Eqi "unknown option|Usage: google-drive-ocamlfuse"; then
echo "!! entrypoint logs:" >&2
echo "$ENTRY_LOGS" | tail -n 20 >&2
fail "entrypoint passed an option the binary rejects (usage text in logs)"
else
echo "ok - no usage/unknown-option output"
fi
echo ">> assert: entrypoint reached the mounting stage"
if echo "$ENTRY_LOGS" | grep -q "Run Mounting App"; then
echo "ok - mounting stage reached"
else
echo "!! entrypoint logs:" >&2
echo "$ENTRY_LOGS" | tail -n 20 >&2
fail "entrypoint never reached the mounting stage"
fi
echo ">> assert: process is waiting for auth (still running or auth URL shown)"
if docker ps --format '{{.Names}}' | grep -q "^${ENTRYNAME}$" \
|| echo "$ENTRY_LOGS" | grep -q "VISIT THE FOLLOWING URL"; then
echo "ok - blocked on OAuth as expected without credentials"
else
echo "!! entrypoint logs:" >&2
echo "$ENTRY_LOGS" | tail -n 20 >&2
fail "entrypoint exited instead of waiting for authorization"
fi
echo
if [ "$FAILED" -eq 0 ]; then
echo "ALL TESTS PASSED"
echo "(note: a full Google Drive mount is not tested - it requires interactive OAuth credentials)"
exit 0
else
echo "SOME TESTS FAILED"
exit 1
fi