mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 11:16:37 +08:00
Stabilize smoke startup port
This commit is contained in:
@@ -71,5 +71,3 @@ jobs:
|
|||||||
run: cd web && npm ci && npm run build
|
run: cd web && npm ci && npm run build
|
||||||
- name: Run smoke test
|
- name: Run smoke test
|
||||||
run: ./scripts/smoke-test.sh
|
run: ./scripts/smoke-test.sh
|
||||||
env:
|
|
||||||
PORT: 18080
|
|
||||||
|
|||||||
+40
-10
@@ -20,7 +20,16 @@
|
|||||||
# =============================================================================
|
# =============================================================================
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
PORT="${PORT:-18080}"
|
if [ -z "${PORT:-}" ]; then
|
||||||
|
PORT="$(python3 - <<'PY'
|
||||||
|
import socket
|
||||||
|
s = socket.socket()
|
||||||
|
s.bind(("127.0.0.1", 0))
|
||||||
|
print(s.getsockname()[1])
|
||||||
|
s.close()
|
||||||
|
PY
|
||||||
|
)"
|
||||||
|
fi
|
||||||
ROOT="$(mktemp -d -t msgo-smoke.XXXXXX)"
|
ROOT="$(mktemp -d -t msgo-smoke.XXXXXX)"
|
||||||
DATA="$ROOT/data"
|
DATA="$ROOT/data"
|
||||||
CACHE="$ROOT/cache"
|
CACHE="$ROOT/cache"
|
||||||
@@ -119,10 +128,17 @@ curl -s "http://127.0.0.1:$PORT/api/health" | grep -q '"ok"' && ok "/api/health"
|
|||||||
|
|
||||||
# --- 3. Auth ----------------------------------------------------------------
|
# --- 3. Auth ----------------------------------------------------------------
|
||||||
hdr "Auth"
|
hdr "Auth"
|
||||||
TOKEN=$(curl -s -X POST -H 'Content-Type: application/json' \
|
LOGIN_JSON=$(curl -s -X POST -H 'Content-Type: application/json' \
|
||||||
-d '{"username":"admin","password":"smoketest12345"}' \
|
-d '{"username":"admin","password":"smoketest12345"}' \
|
||||||
"http://127.0.0.1:$PORT/api/auth/login" | json_token)
|
"http://127.0.0.1:$PORT/api/auth/login")
|
||||||
[ -n "$TOKEN" ] && ok "login as admin" || fail "login as admin"
|
TOKEN=$(printf '%s' "$LOGIN_JSON" | json_token || true)
|
||||||
|
if [ -n "$TOKEN" ]; then
|
||||||
|
ok "login as admin"
|
||||||
|
else
|
||||||
|
fail "login as admin"
|
||||||
|
printf "login response: %s\n" "$LOGIN_JSON"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
H="Authorization: Bearer $TOKEN"
|
H="Authorization: Bearer $TOKEN"
|
||||||
curl -s -o /dev/null -w "%{http_code}" -H "$H" "http://127.0.0.1:$PORT/api/me" | grep -q 200 \
|
curl -s -o /dev/null -w "%{http_code}" -H "$H" "http://127.0.0.1:$PORT/api/me" | grep -q 200 \
|
||||||
&& ok "/api/me with bearer" || fail "/api/me with bearer"
|
&& ok "/api/me with bearer" || fail "/api/me with bearer"
|
||||||
@@ -131,15 +147,29 @@ curl -s -o /dev/null -w "%{http_code}" "http://127.0.0.1:$PORT/api/me" | grep -q
|
|||||||
|
|
||||||
# --- 4. Library + scan ------------------------------------------------------
|
# --- 4. Library + scan ------------------------------------------------------
|
||||||
hdr "Library + scan + search"
|
hdr "Library + scan + search"
|
||||||
MOVIE=$(curl -s -X POST -H "$H" -H 'Content-Type: application/json' \
|
MOVIE_JSON=$(curl -s -X POST -H "$H" -H 'Content-Type: application/json' \
|
||||||
-d "{\"name\":\"movies\",\"path\":\"$MEDIA/movies\",\"type\":\"movie\"}" \
|
-d "{\"name\":\"movies\",\"path\":\"$MEDIA/movies\",\"type\":\"movie\"}" \
|
||||||
"http://127.0.0.1:$PORT/api/libraries" | python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])')
|
"http://127.0.0.1:$PORT/api/libraries")
|
||||||
[ -n "$MOVIE" ] && ok "create movie library" || fail "create movie library"
|
MOVIE=$(printf '%s' "$MOVIE_JSON" | python3 -c 'import json,sys;print(json.load(sys.stdin).get("id", ""))' || true)
|
||||||
|
if [ -n "$MOVIE" ]; then
|
||||||
|
ok "create movie library"
|
||||||
|
else
|
||||||
|
fail "create movie library"
|
||||||
|
printf "create movie library response: %s\n" "$MOVIE_JSON"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
TV=$(curl -s -X POST -H "$H" -H 'Content-Type: application/json' \
|
TV_JSON=$(curl -s -X POST -H "$H" -H 'Content-Type: application/json' \
|
||||||
-d "{\"name\":\"tv\",\"path\":\"$MEDIA/tv\",\"type\":\"tv\"}" \
|
-d "{\"name\":\"tv\",\"path\":\"$MEDIA/tv\",\"type\":\"tv\"}" \
|
||||||
"http://127.0.0.1:$PORT/api/libraries" | python3 -c 'import json,sys;print(json.load(sys.stdin)["id"])')
|
"http://127.0.0.1:$PORT/api/libraries")
|
||||||
[ -n "$TV" ] && ok "create tv library" || fail "create tv library"
|
TV=$(printf '%s' "$TV_JSON" | python3 -c 'import json,sys;print(json.load(sys.stdin).get("id", ""))' || true)
|
||||||
|
if [ -n "$TV" ]; then
|
||||||
|
ok "create tv library"
|
||||||
|
else
|
||||||
|
fail "create tv library"
|
||||||
|
printf "create tv library response: %s\n" "$TV_JSON"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
RES=$(curl -s -X POST -H "$H" "http://127.0.0.1:$PORT/api/libraries/$MOVIE/scan")
|
RES=$(curl -s -X POST -H "$H" "http://127.0.0.1:$PORT/api/libraries/$MOVIE/scan")
|
||||||
ADDED=$(echo "$RES" | python3 -c 'import json,sys;print(json.load(sys.stdin)["added"])')
|
ADDED=$(echo "$RES" | python3 -c 'import json,sys;print(json.load(sys.stdin)["added"])')
|
||||||
|
|||||||
Reference in New Issue
Block a user