Repository navigation
Expand file tree
/
Copy pathtest-api-params.sh
More file actions
executable file
·64 lines (56 loc) · 2.11 KB
/
Copy pathtest-api-params.sh
File metadata and controls
executable file
·64 lines (56 loc) · 2.11 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
#!/bin/bash
# 测试脚本:验证前端参数传递到后端
API_BASE="http://localhost:8080/api"
echo "=== 步骤1: 获取可用的KubeConfig ==="
curl -s "$API_BASE/kubeconfig" | jq '.[0].id' > kubeconfig_id.txt
KUBECONFIG_ID=$(cat kubeconfig_id.txt | tr -d '"')
echo "使用KubeConfigID: $KUBECONFIG_ID"
echo ""
echo "=== 步骤2: 测试创建应用 (完整参数) ==="
curl -X POST "$API_BASE/applications" \
-H "Content-Type: application/json" \
-d "{
\"name\": \"test-full-params\",
\"namespace\": \"default\",
\"kubeConfigID\": \"$KUBECONFIG_ID\",
\"description\": \"测试完整参数传递\",
\"imageName\": \"nginx:latest\",
\"imageURL\": \"nginx:latest\",
\"replicas\": 2,
\"port\": 80,
\"serviceType\": \"ClusterIP\",
\"cpuRequest\": \"100m\",
\"cpuLimit\": \"500m\",
\"memoryRequest\": \"128Mi\",
\"memoryLimit\": \"512Mi\",
\"imagePullPolicy\": \"IfNotPresent\",
\"updateStrategy\": \"RollingUpdate\",
\"rollingUpdate\": {\"maxUnavailable\": \"25%\", \"maxSurge\": \"25%\"},
\"envVars\": [],
\"volumes\": [],
\"nodeSelector\": {},
\"syncHostTimezone\": false
}" | jq '.'
echo ""
echo "=== 步骤3: 测试创建应用 (最小参数) ==="
curl -X POST "$API_BASE/applications" \
-H "Content-Type: application/json" \
-d "{
\"name\": \"test-minimal-params\",
\"namespace\": \"default\",
\"kubeConfigID\": \"$KUBECONFIG_ID\",
\"imageName\": \"nginx:latest\",
\"replicas\": 1
}" | jq '.'
echo ""
echo "=== 步骤4: 检查应用列表 ==="
curl -s "$API_BASE/applications" | jq '.[] | select(.appName | startswith("test-")) | {name: .appName, cpu: .cpu, memory: .memory, status: .status}'
echo ""
echo "=== 步骤5: 获取应用详情 (检查资源限制) ==="
APP_ID=$(curl -s "$API_BASE/applications" | jq -r '.[] | select(.appName == "test-full-params") | .id')
if [ "$APP_ID" != "null" ]; then
echo "应用ID: $APP_ID"
curl -s "$API_BASE/applications/$APP_ID" | jq '{name: .appName, cpuRequest: .cpuRequest, cpuLimit: .cpuLimit, memoryRequest: .memoryRequest, memoryLimit: .memoryLimit}'
fi
# 清理
rm -f kubeconfig_id.txt