-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·70 lines (56 loc) · 1.84 KB
/
test.sh
File metadata and controls
executable file
·70 lines (56 loc) · 1.84 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
#!/usr/bin/env bash
set -euo pipefail
HOST="${HOST:-http://localhost:8080}"
TOKEN="${TOKEN:-secret123}"
TAG="${TAG:-v0.0.13}"
FILE="${FILE:-docker-compose.yml}"
AUTH="Authorization: Bearer $TOKEN"
CT="Content-Type: application/json"
green() { printf '\033[32m%s\033[0m\n' "$*"; }
red() { printf '\033[31m%s\033[0m\n' "$*"; }
header() { echo; green "=== $* ==="; }
# --- Tests ---
header "GET /version"
curl -s "$HOST/version" | jq .
header "POST /compose/up (streaming)"
curl -sN "$HOST/compose/up" \
-H "$AUTH" -H "$CT" \
-d "{\"tag\": \"$TAG\", \"file\": \"$FILE\"}"
echo
header "POST /compose/logs"
curl -s "$HOST/compose/logs" \
-H "$AUTH" -H "$CT" \
-d "{\"file\": \"$FILE\", \"tail\": 10}" | jq .
header "GET /docker/ps"
curl -s "$HOST/docker/ps" \
-H "$AUTH" | jq .
header "POST /docker/restart (first container from docker ps)"
CONTAINER=$(curl -s "$HOST/docker/ps" -H "$AUTH" | jq -r '.output' | head -1 | jq -r '.Names')
if [ -n "$CONTAINER" ] && [ "$CONTAINER" != "null" ]; then
echo "Restarting container: $CONTAINER"
curl -s "$HOST/docker/restart" \
-H "$AUTH" -H "$CT" \
-d "{\"container\": \"$CONTAINER\"}" | jq .
else
red "No containers found, skipping restart test"
fi
header "POST /compose/down (streaming)"
curl -sN "$HOST/compose/down" \
-H "$AUTH" -H "$CT" \
-d "{\"tag\": \"$TAG\", \"file\": \"$FILE\"}"
echo
header "POST /compose/up with env vars (streaming)"
curl -sN "$HOST/compose/up" \
-H "$AUTH" -H "$CT" \
-d "{\"tag\": \"$TAG\", \"file\": \"$FILE\", \"env\": {\"MY_VAR\": \"hello\"}}"
echo
header "POST /compose/down (cleanup)"
curl -sN "$HOST/compose/down" \
-H "$AUTH" -H "$CT" \
-d "{\"tag\": \"$TAG\", \"file\": \"$FILE\"}"
echo
header "POST /docker/clean (volumes)"
curl -s "$HOST/docker/clean" \
-H "$AUTH" -H "$CT" \
-d '{"volumes": true, "images": false}' | jq .
green "All tests completed."