-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·92 lines (79 loc) · 2.33 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·92 lines (79 loc) · 2.33 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
#!/bin/sh
# automated smoke test for the quark container
# builds the image, serves a docroot and asserts quark actually serves it over HTTP
set -eu
IMAGE=quark-test
NAME=quark-test-run
MARKER="quark-smoke-test-$$-ok"
FAILED=0
fail() {
echo "FAIL: $*" >&2
FAILED=1
}
cleanup() {
echo ">> cleanup: removing container $NAME"
docker rm -f "$NAME" >/dev/null 2>&1 || true
}
trap cleanup EXIT INT TERM
echo ">> building image $IMAGE"
docker build -t "$IMAGE" .
echo ">> (re)starting container $NAME"
docker rm -f "$NAME" >/dev/null 2>&1 || true
# quark serves /data on port 80 (see Dockerfile CMD)
docker run -d --name "$NAME" "$IMAGE"
echo ">> waiting for quark to come up (up to ~30s)"
READY=0
i=0
while [ "$i" -lt 15 ]; do
if ! docker ps --format '{{.Names}}' | grep -q "^${NAME}$"; then
echo "!! container is not running anymore, dumping logs:" >&2
docker logs "$NAME" >&2 2>&1 || true
fail "container exited during startup"
break
fi
if docker exec "$NAME" ps aux 2>/dev/null | grep -q '[q]uark'; then
READY=1
break
fi
i=$((i + 1))
sleep 2
done
if [ "$READY" -ne 1 ] && [ "$FAILED" -eq 0 ]; then
echo "!! quark did not come up in time, dumping logs:" >&2
docker logs "$NAME" >&2 2>&1 || true
fail "timed out waiting for quark"
fi
if docker ps --format '{{.Names}}' | grep -q "^${NAME}$"; then
echo ">> assert: quark process present"
if docker exec "$NAME" ps aux | grep -q '[q]uark'; then
echo "ok - quark running"
else
fail "quark process not found"
fi
# write the marker into quark's docroot inside the container (no host bind-mount,
# so this behaves identically locally and on CI runners)
echo ">> placing marker file into /data"
docker exec "$NAME" sh -c "printf '%s' '$MARKER' > /data/index.html" || fail "could not write into /data"
echo ">> assert: quark serves the file over HTTP with the right content"
BODY=""
n=0
while [ "$n" -lt 15 ]; do
BODY=$(docker exec "$NAME" wget -qO- http://127.0.0.1:80/index.html 2>/dev/null || true)
[ "$BODY" = "$MARKER" ] && break
n=$((n + 1))
sleep 1
done
if [ "$BODY" = "$MARKER" ]; then
echo "ok - HTTP response matched marker ($MARKER)"
else
fail "HTTP response did not match marker (got: '$BODY')"
fi
fi
echo
if [ "$FAILED" -eq 0 ]; then
echo "ALL TESTS PASSED"
exit 0
else
echo "SOME TESTS FAILED"
exit 1
fi