-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-daemon-simple.sh
More file actions
executable file
·85 lines (70 loc) · 1.92 KB
/
test-daemon-simple.sh
File metadata and controls
executable file
·85 lines (70 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# 简化版 E2E 测试脚本
set -e
echo "=== Procman Daemon E2E Tests ==="
# 确保二进制文件存在
if [ ! -f "./procman" ]; then
echo "Building procman..."
go build -o procman ./cmd/procman
fi
# 测试端口
TEST_PORT=18080
PID_FILE="/tmp/procman-test.pid"
# 清理函数
cleanup() {
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if kill -0 "$PID" 2>/dev/null; then
echo "Stopping daemon (PID: $PID)..."
kill "$PID"
sleep 1
fi
rm -f "$PID_FILE"
fi
}
# 注册清理
trap cleanup EXIT
# 测试 1: 前台模式
echo "1. Testing foreground mode..."
timeout 5s ./procman -port $TEST_PORT run &
PROC_PID=$!
sleep 2
# 测试 HTTP 端点
if curl -s "http://localhost:$TEST_PORT/api/hello" | grep -q "Hello World"; then
echo "✅ Root endpoint works"
else
echo "❌ Root endpoint failed"
exit 1
fi
if curl -s "http://localhost:$TEST_PORT/health" | grep -q "healthy"; then
echo "✅ Health endpoint works"
else
echo "❌ Health endpoint failed"
exit 1
fi
# 停止前台进程
kill $PROC_PID 2>/dev/null || true
wait $PROC_PID 2>/dev/null || true
echo "✅ Foreground mode test passed"
# 测试 2: 配置加载
echo "2. Testing configuration..."
echo "port: $TEST_PORT" > test-config.yaml
./procman -config test-config.yaml status > /dev/null 2>&1
echo "✅ Configuration loading works"
# 测试 3: 环境变量
echo "3. Testing environment variables..."
PROCMAN_PORT=$TEST_PORT ./procman status > /dev/null 2>&1
echo "✅ Environment variables work"
# 测试 4: 帮助命令
echo "4. Testing help command..."
./procman --help > /dev/null
echo "✅ Help command works"
# 清理
rm -f test-config.yaml
echo ""
echo "=== All Tests Passed! ==="
echo "Daemon capabilities verified:"
echo " ✅ HTTP server functionality"
echo " ✅ Configuration management"
echo " ✅ Environment variable support"
echo " ✅ Command-line interface"