-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·60 lines (50 loc) · 2.32 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·60 lines (50 loc) · 2.32 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
#!/bin/sh
# Automated smoke test for the tvheadend container.
# Builds the image, runs it, waits for tvheadend to listen on 9981 and asserts
# that it actually serves the web UI (not just an open port) by checking the
# HTTP response looks like tvheadend (HTS/tvheadend server, redirect to /gui/).
set -e
IMG=tvheadend-test
CN=tvheadend-test-run
cleanup() { docker rm -f "$CN" >/dev/null 2>&1 || true; }
trap cleanup EXIT
fail() { echo "FAIL: $1"; exit 1; }
echo ">> building image"
docker build -t "$IMG" .
echo ">> starting container"
docker rm -f "$CN" >/dev/null 2>&1 || true
# runs tvheadend -C: creates an admin account with no password on first run,
# so the web UI comes up without needing any extra env/config.
docker run -d --name "$CN" "$IMG" >/dev/null
echo ">> waiting for tvheadend to listen on 9981 (up to 120s)"
up=0
for _ in $(seq 1 60); do
if docker exec "$CN" bash -c 'exec 3<>/dev/tcp/127.0.0.1/9981' 2>/dev/null; then up=1; break; fi
sleep 2
done
[ "$up" = 1 ] || fail "tvheadend did not start listening on 9981 in time"
echo "ok - port 9981 open"
echo ">> assert: container is running"
[ "$(docker inspect -f '{{.State.Running}}' "$CN")" = true ] || fail "container not running"
echo "ok - container running"
echo ">> assert: tvheadend process present"
# the image has no procps (ps), so look it up via /proc comm entries instead
docker exec "$CN" sh -c 'grep -qx tvheadend /proc/*/comm 2>/dev/null' || fail "tvheadend process not running"
echo "ok - tvheadend running"
echo ">> assert: HTTP on 9981 serves tvheadend (not just an open port)"
resp=$(docker exec "$CN" curl -s -i http://127.0.0.1:9981/ 2>/dev/null || true)
[ -n "$resp" ] || fail "no HTTP response from tvheadend on 9981"
# a real tvheadend answers with the 'HTS/tvheadend' server banner and, when the
# fresh admin account has no password, redirects '/' to the '/gui/' web UI. Any
# of these markers proves it's tvheadend responding rather than a dead socket.
if echo "$resp" | grep -qi 'HTS/tvheadend' \
|| echo "$resp" | grep -qi 'Location: */gui' \
|| echo "$resp" | grep -qi 'WWW-Authenticate' \
|| echo "$resp" | grep -qi 'tvheadend'; then
echo "ok - tvheadend served an HTTP response:"
echo "$resp" | head -3 | sed 's/^/ /'
else
fail "HTTP response does not look like tvheadend (got: $(echo "$resp" | head -1))"
fi
echo ""
echo "ALL TESTS PASSED"