Skip to content

Commit 553b8a8

Browse files
committed
ci(workflow): 增强集成测试工作流以支持 Docker 容器备份测试
- 启动测试容器并将其名称传递给回调处理程序 - 在失败时输出应用和容器日志以方便调试 - 测试结束后清理测试容器 ci(workflow): enhance integration test workflow to support docker container backup testing - start a test container and pass its name to the callback handler - output app and container logs on failure for easier debugging - cleanup the test container after tests complete
1 parent 7f196d9 commit 553b8a8

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

.github/workflows/go-test.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ jobs:
4141
4242
- name: Run integration test
4343
run: |
44+
# Start a test container for backup
45+
echo "Starting a test Docker container..."
46+
docker run -d --name test-container nginx:alpine
47+
echo "Test container started."
48+
4449
# Start the callback handler application in the background
4550
nohup ./myapp > app.log 2>&1 &
4651
@@ -55,11 +60,12 @@ jobs:
5560
done
5661
5762
# Prepare and send a simulated external callback (POST request)
58-
SIGNATURE=$(echo -n '{"args":[]}' | openssl dgst -sha256 -hmac "my-test-secret" | sed 's/^.* //')
63+
# Include the test container name in the args
64+
SIGNATURE=$(echo -n '{"args":["test-container"]}' | openssl dgst -sha256 -hmac "my-test-secret" | sed 's/^.* //')
5965
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST http://localhost:8080/backup \
6066
-H "Content-Type: application/json" \
6167
-H "X-Signature: sha256=$SIGNATURE" \
62-
-d '{"args":[]}')
68+
-d '{"args":["test-container"]}')
6369
6470
# Extract response body and status code
6571
RESPONSE_BODY=$(echo "$RESPONSE" | head -n -1)
@@ -69,19 +75,36 @@ jobs:
6975
if [ "$STATUS_CODE" != "200" ]; then
7076
echo "Test failed: Expected status code 200, got $STATUS_CODE"
7177
echo "Response: $RESPONSE_BODY"
78+
# Output app logs for debugging
79+
echo "=== App logs ==="
80+
cat app.log
81+
echo "=== End of app logs ==="
82+
# Output Docker logs for the test container
83+
echo "=== Test container logs ==="
84+
docker logs test-container || true
85+
echo "=== End of test container logs ==="
7286
exit 1
7387
fi
7488
7589
if [[ "$RESPONSE_BODY" != *"Backup initiated successfully"* ]]; then
7690
echo "Test failed: Expected response body to contain 'Backup initiated successfully'"
7791
echo "Response: $RESPONSE_BODY"
92+
# Output app logs for debugging
93+
echo "=== App logs ==="
94+
cat app.log
95+
echo "=== End of app logs ==="
96+
# Output Docker logs for the test container
97+
echo "=== Test container logs ==="
98+
docker logs test-container || true
99+
echo "=== End of test container logs ==="
78100
exit 1
79101
fi
80102
81103
echo "Callback handler test passed"
82104
83105
# Cleanup
84106
killall myapp || true
107+
docker rm -f test-container || true
85108
86109
- name: Output application logs
87110
if: always()
@@ -94,7 +117,7 @@ jobs:
94117
# List directories that match the backup pattern created by docker-backup.sh
95118
echo "Backup directories:"
96119
ls -la /tmp/docker-backups/ 2>/dev/null || echo "No backup directory found at /tmp/docker-backups/"
97-
120+
98121
# If backup directories exist, show their contents
99122
if [[ -d "/tmp/docker-backups" ]]; then
100123
for backup_dir in /tmp/docker-backups/*/; do

0 commit comments

Comments
 (0)