98 lines
2.4 KiB
Bash
Executable File
98 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
echo "=== tingz Service Test ==="
|
|
echo "This test script assumes you've deployed the service with .env.development file."
|
|
echo "If you haven't, stop running containers, and run `docker compose --env-file .env.development up -d`"
|
|
echo
|
|
|
|
BASE_URL="http://127.0.0.1:8080"
|
|
ADMIN_TOKEN="devadmintoken"
|
|
|
|
echo "1. Testing health endpoint..."
|
|
curl -s "${BASE_URL}/api/v1/status" | jq .
|
|
echo
|
|
|
|
echo "2. Creating user 'testuser'..."
|
|
RESPONSE=$(curl -s -X POST "${BASE_URL}/api/v1/auth" \
|
|
-H "Authorization: Bearer ${ADMIN_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"username":"testuser"}')
|
|
|
|
echo "$RESPONSE" | jq .
|
|
USER_TOKEN=$(echo "$RESPONSE" | jq -r .token)
|
|
|
|
if [ "$USER_TOKEN" = "null" ] || [ -z "$USER_TOKEN" ]; then
|
|
echo "Error: Failed to create user or extract token"
|
|
exit 1
|
|
fi
|
|
|
|
echo "User token: $USER_TOKEN"
|
|
echo
|
|
|
|
echo "3. Creating test static site..."
|
|
TEST_DIR=$(mktemp -d)
|
|
cat > "${TEST_DIR}/index.html" << 'EOF'
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head><title>Test Deployment</title></head>
|
|
<body><h1>Hello from Deployer Service!</h1></body>
|
|
</html>
|
|
EOF
|
|
|
|
echo "4. Creating tarball..."
|
|
TARBALL="${TEST_DIR}/site.tar.gz"
|
|
tar -czf "$TARBALL" -C "$TEST_DIR" index.html
|
|
echo "Tarball created: $TARBALL"
|
|
echo
|
|
|
|
echo "5. Deploying to project 'testproject'..."
|
|
DEPLOY_RESPONSE=$(curl -s -X POST "${BASE_URL}/api/v1/deploy" \
|
|
-H "Authorization: Bearer ${USER_TOKEN}" \
|
|
-F "project=testproject" \
|
|
-F "file=@${TARBALL}")
|
|
|
|
echo "$DEPLOY_RESPONSE" | jq .
|
|
echo
|
|
|
|
DEPLOY_STATUS=$(echo "$DEPLOY_RESPONSE" | jq -r .status)
|
|
if [ "$DEPLOY_STATUS" != "ok" ]; then
|
|
echo "Error: Deployment failed"
|
|
exit 1
|
|
fi
|
|
|
|
echo "6. Verifying deployment files..."
|
|
RELEASE_ID=$(echo "$DEPLOY_RESPONSE" | jq -r .release)
|
|
echo "Release ID: $RELEASE_ID"
|
|
|
|
if [ -d "deploys/testuser/testproject/${RELEASE_ID}" ]; then
|
|
echo "✓ Release directory exists"
|
|
ls -la "deploys/testuser/testproject/${RELEASE_ID}/"
|
|
else
|
|
echo "✗ Release directory not found"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -L "docs/testuser/testproject" ]; then
|
|
echo "✓ Symlink exists"
|
|
ls -la "docs/testuser/testproject"
|
|
else
|
|
echo "✗ Symlink not found"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -f "docs/testuser/testproject/index.html" ]; then
|
|
echo "✓ index.html is accessible"
|
|
cat "docs/testuser/testproject/index.html"
|
|
else
|
|
echo "✗ index.html not found"
|
|
exit 1
|
|
fi
|
|
|
|
echo
|
|
echo "7. Cleaning up test files..."
|
|
rm -rf "$TEST_DIR"
|
|
|
|
echo
|
|
echo "=== All tests passed! ==="
|