Files
dl/tests/test.sh
T
opencodecabilloteu ff0286e02d
Docker Build and Push / lint (pull_request) Failing after 7s
Docker Build and Push / build (pull_request) Successful in 2m10s
Docker Build and Push / test (pull_request) Has been skipped
Docker Build and Push / push (pull_request) Has been skipped
feat: add lint, build, test, push pipeline with SHA-pinned actions
- Split single build job into 4 jobs: lint, build, test, push
- SHA-pin all actions for supply chain security
- Use ChristopherHX artifact actions (Gitea-compatible)
- Add tests/test.sh with Docker bridge gateway networking
- Test GET / returns jQuery File Upload HTML
2026-06-08 19:11:35 +00:00

73 lines
1.9 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
IMAGE="${1:?Usage: test.sh <image>}"
CONTAINER_NAME="test-$(echo "$IMAGE" | tr ':/' '-')-$$"
PASSED=0
FAILED=0
TOTAL=0
cleanup() {
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
}
trap cleanup EXIT
assert() {
local name="$1" expected="$2" actual="$3"
TOTAL=$((TOTAL + 1))
if [ "$expected" = "$actual" ]; then
echo " PASS: $name"
PASSED=$((PASSED + 1))
else
echo " FAIL: $name (expected: '$expected', got: '$actual')"
FAILED=$((FAILED + 1))
fi
}
assert_match() {
local name="$1" pattern="$2" actual="$3"
TOTAL=$((TOTAL + 1))
if echo "$actual" | grep -qE "$pattern"; then
echo " PASS: $name"
PASSED=$((PASSED + 1))
else
echo " FAIL: $name (pattern: '$pattern', got: '$actual')"
FAILED=$((FAILED + 1))
fi
}
echo "Running container: $IMAGE"
docker run -d --name "$CONTAINER_NAME" -p 8080:8080 "$IMAGE" >/dev/null
DOCKER_GW=$(docker network inspect bridge --format '{{range .IPAM.Config}}{{.Gateway}}{{end}}')
BASE_URL="http://${DOCKER_GW}:8080"
echo "Waiting for container on ${DOCKER_GW}:8080..."
for i in $(seq 1 30); do
if curl -sf "$BASE_URL/" >/dev/null 2>&1; then
echo "Container ready after ${i}s"
break
fi
if [ "$i" -eq 30 ]; then
echo "FAIL: Container did not become ready within 30s"
docker logs "$CONTAINER_NAME"
exit 1
fi
sleep 1
done
echo ""
echo "Test: GET /"
RESPONSE=$(curl -sf -D - "$BASE_URL/")
STATUS=$(echo "$RESPONSE" | head -1 | grep -oP '\d{3}')
CONTENT_TYPE=$(echo "$RESPONSE" | grep -i 'content-type' | tr -d '\r' | cut -d: -f2- | xargs)
BODY=$(echo "$RESPONSE" | sed -n '/^\r$/,$p' | tail -n +2)
assert "HTTP status is 200" "200" "$STATUS"
assert_match "Content-Type is text/html" "text/html" "$CONTENT_TYPE"
assert_match "Body contains file upload UI" "[Ff]ile.?[Uu]pload" "$BODY"
echo ""
echo "Results: $PASSED/$TOTAL passed, $FAILED failed"
[ "$FAILED" -eq 0 ]