Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
DEPLOY_DIR="$(cd "${TEST_DIR}/.." && pwd)"
|
||||
SCRIPT="${DEPLOY_DIR}/apple-container.sh"
|
||||
TEST_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/sub2api-apple-test.XXXXXX")"
|
||||
STATE_DIR="${TEST_ROOT}/state"
|
||||
ENV_FILE="${TEST_ROOT}/sub2api.env"
|
||||
|
||||
cleanup() {
|
||||
rm -rf "${TEST_ROOT}"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
fail() {
|
||||
printf 'FAIL: %s\n' "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
assert_exists() {
|
||||
[[ -e "$1" ]] || fail "Expected path to exist: $1"
|
||||
}
|
||||
|
||||
assert_missing() {
|
||||
[[ ! -e "$1" ]] || fail "Expected path to be absent: $1"
|
||||
}
|
||||
|
||||
export FAKE_CONTAINER_STATE="${STATE_DIR}"
|
||||
export PATH="${TEST_DIR}/fixtures/bin:${PATH}"
|
||||
export SUB2API_ENV_FILE="${ENV_FILE}"
|
||||
|
||||
mkdir -p "${STATE_DIR}"
|
||||
|
||||
"${SCRIPT}" init
|
||||
[[ "$(stat -f '%Lp' "${ENV_FILE}")" == "600" ]] || fail "init did not create a mode-600 env file"
|
||||
grep -q '^POSTGRES_PASSWORD=change_this_secure_password$' "${ENV_FILE}" && fail "init retained the placeholder password"
|
||||
|
||||
chmod 644 "${ENV_FILE}"
|
||||
if "${SCRIPT}" up >/dev/null 2>&1; then
|
||||
fail "up accepted an insecure env file"
|
||||
fi
|
||||
chmod 600 "${ENV_FILE}"
|
||||
|
||||
"${SCRIPT}" up
|
||||
assert_exists "${STATE_DIR}/containers/sub2api-apple"
|
||||
assert_exists "${STATE_DIR}/containers/sub2api-apple-postgres"
|
||||
assert_exists "${STATE_DIR}/containers/sub2api-apple-redis"
|
||||
assert_exists "${STATE_DIR}/running/sub2api-apple"
|
||||
"${SCRIPT}" status >/dev/null
|
||||
|
||||
"${SCRIPT}" up --recreate
|
||||
assert_exists "${STATE_DIR}/running/sub2api-apple"
|
||||
"${SCRIPT}" down
|
||||
assert_missing "${STATE_DIR}/running/sub2api-apple"
|
||||
assert_missing "${STATE_DIR}/running/sub2api-apple-postgres"
|
||||
assert_missing "${STATE_DIR}/running/sub2api-apple-redis"
|
||||
|
||||
"${SCRIPT}" destroy --yes
|
||||
assert_missing "${STATE_DIR}/containers/sub2api-apple"
|
||||
assert_missing "${STATE_DIR}/networks/sub2api-apple"
|
||||
assert_exists "${STATE_DIR}/volumes/sub2api-apple-data"
|
||||
|
||||
"${SCRIPT}" up
|
||||
"${SCRIPT}" destroy --volumes --yes
|
||||
assert_missing "${STATE_DIR}/volumes/sub2api-apple-data"
|
||||
assert_missing "${STATE_DIR}/volumes/sub2api-apple-postgres-data"
|
||||
assert_missing "${STATE_DIR}/volumes/sub2api-apple-redis-data"
|
||||
|
||||
touch "${STATE_DIR}/system-running"
|
||||
touch "${STATE_DIR}/containers/sub2api-apple"
|
||||
touch "${STATE_DIR}/unowned/container/sub2api-apple"
|
||||
if "${SCRIPT}" status >/dev/null 2>&1; then
|
||||
fail "status accepted an unowned same-name container"
|
||||
fi
|
||||
|
||||
printf 'Apple container lifecycle tests passed.\n'
|
||||
Reference in New Issue
Block a user