@sokeai/cli 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/e2e-test.sh +207 -0
- package/scripts/release.sh +13 -3
package/package.json
CHANGED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# soke-cli 端到端测试脚本
|
|
4
|
+
# 测试所有命令是否能正常执行
|
|
5
|
+
# 支持按模块测试: ./e2e-test.sh [module_name]
|
|
6
|
+
|
|
7
|
+
# 注意:不使用 set -e,让所有测试都能运行完
|
|
8
|
+
|
|
9
|
+
# 颜色输出
|
|
10
|
+
RED='\033[0;31m'
|
|
11
|
+
GREEN='\033[0;32m'
|
|
12
|
+
YELLOW='\033[1;33m'
|
|
13
|
+
BLUE='\033[0;34m'
|
|
14
|
+
NC='\033[0m'
|
|
15
|
+
|
|
16
|
+
# 测试结果统计
|
|
17
|
+
TOTAL_TESTS=0
|
|
18
|
+
PASSED_TESTS=0
|
|
19
|
+
FAILED_TESTS=0
|
|
20
|
+
FAILED_COMMANDS=()
|
|
21
|
+
|
|
22
|
+
# 获取版本号
|
|
23
|
+
VERSION=$(node -p "require('./package.json').version")
|
|
24
|
+
|
|
25
|
+
# 获取要测试的模块(如果指定)
|
|
26
|
+
TEST_MODULE=$1
|
|
27
|
+
|
|
28
|
+
echo -e "${BLUE}========================================${NC}"
|
|
29
|
+
if [ -z "$TEST_MODULE" ]; then
|
|
30
|
+
echo -e "${BLUE} soke-cli E2E 测试 v${VERSION}${NC}"
|
|
31
|
+
else
|
|
32
|
+
echo -e "${BLUE} soke-cli E2E 测试 - ${TEST_MODULE} 模块${NC}"
|
|
33
|
+
fi
|
|
34
|
+
echo -e "${BLUE}========================================${NC}"
|
|
35
|
+
echo ""
|
|
36
|
+
|
|
37
|
+
# 检查是否已编译
|
|
38
|
+
if [ ! -f "./soke-cli" ]; then
|
|
39
|
+
echo -e "${YELLOW}未找到编译文件,开始编译...${NC}"
|
|
40
|
+
go build -o soke-cli main.go
|
|
41
|
+
echo -e "${GREEN}✓ 编译完成${NC}"
|
|
42
|
+
echo ""
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# 检查是否已登录
|
|
46
|
+
echo -e "${YELLOW}检查登录状态...${NC}"
|
|
47
|
+
if ! ./soke-cli config show &>/dev/null; then
|
|
48
|
+
echo -e "${RED}错误: 未配置或未登录${NC}"
|
|
49
|
+
echo "请先运行: ./soke-cli config init && ./soke-cli auth login"
|
|
50
|
+
exit 1
|
|
51
|
+
fi
|
|
52
|
+
echo -e "${GREEN}✓ 已登录${NC}"
|
|
53
|
+
echo ""
|
|
54
|
+
|
|
55
|
+
# 测试函数
|
|
56
|
+
test_command() {
|
|
57
|
+
local module=$1
|
|
58
|
+
local command=$2
|
|
59
|
+
local args=$3
|
|
60
|
+
local description=$4
|
|
61
|
+
|
|
62
|
+
TOTAL_TESTS=$((TOTAL_TESTS + 1))
|
|
63
|
+
|
|
64
|
+
echo -n "测试 [$module $command]: $description ... "
|
|
65
|
+
|
|
66
|
+
if ./soke-cli $module $command $args &>/dev/null; then
|
|
67
|
+
echo -e "${GREEN}✓ 通过${NC}"
|
|
68
|
+
PASSED_TESTS=$((PASSED_TESTS + 1))
|
|
69
|
+
return 0
|
|
70
|
+
else
|
|
71
|
+
echo -e "${RED}✗ 失败${NC}"
|
|
72
|
+
FAILED_TESTS=$((FAILED_TESTS + 1))
|
|
73
|
+
FAILED_COMMANDS+=("$module $command $args")
|
|
74
|
+
return 1
|
|
75
|
+
fi
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
# 判断是否应该运行某个模块的测试
|
|
79
|
+
should_test_module() {
|
|
80
|
+
local module=$1
|
|
81
|
+
if [ -z "$TEST_MODULE" ]; then
|
|
82
|
+
return 0 # 没有指定模块,测试所有
|
|
83
|
+
elif [ "$TEST_MODULE" = "$module" ]; then
|
|
84
|
+
return 0 # 指定的模块匹配
|
|
85
|
+
else
|
|
86
|
+
return 1 # 不匹配,跳过
|
|
87
|
+
fi
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
echo -e "${BLUE}开始测试...${NC}"
|
|
91
|
+
echo ""
|
|
92
|
+
|
|
93
|
+
# ==================== Contact 模块 ====================
|
|
94
|
+
if should_test_module "contact"; then
|
|
95
|
+
echo -e "${YELLOW}[Contact 模块]${NC}"
|
|
96
|
+
test_command "contact" "+list-departments" "" "获取部门列表"
|
|
97
|
+
test_command "contact" "+get-department" "--dept-id 1" "获取部门详情"
|
|
98
|
+
test_command "contact" "+list-department-users" "--dept-id 1" "获取部门用户列表"
|
|
99
|
+
test_command "contact" "+list-lectors" "" "获取讲师列表"
|
|
100
|
+
test_command "contact" "+list-groups" "--start-time 1672502400000 --end-time 1704038400000" "获取用户组列表"
|
|
101
|
+
test_command "contact" "+search-user" "--dept-user-name 测试" "搜索用户"
|
|
102
|
+
echo ""
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
# ==================== Course 模块 ====================
|
|
106
|
+
if should_test_module "course"; then
|
|
107
|
+
echo -e "${YELLOW}[Course 模块]${NC}"
|
|
108
|
+
test_command "course" "+list-courses" "--start-time 1672502400000 --end-time 1704038400000" "获取课程列表"
|
|
109
|
+
test_command "course" "+list-categories" "" "获取课程分类"
|
|
110
|
+
test_command "course" "+list-lessons" "--course-id F4025496-6566-4ACD-8CD4-06E3D55BBA79" "获取课程章节"
|
|
111
|
+
echo ""
|
|
112
|
+
fi
|
|
113
|
+
|
|
114
|
+
# ==================== Exam 模块 ====================
|
|
115
|
+
if should_test_module "exam"; then
|
|
116
|
+
echo -e "${YELLOW}[Exam 模块]${NC}"
|
|
117
|
+
test_command "exam" "+list-exams" "--start-time 1672502400000 --end-time 1704038400000" "获取考试列表"
|
|
118
|
+
test_command "exam" "+list-categories" "" "获取考试分类"
|
|
119
|
+
echo ""
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
# ==================== Certificate 模块 ====================
|
|
123
|
+
if should_test_module "certificate"; then
|
|
124
|
+
echo -e "${YELLOW}[Certificate 模块]${NC}"
|
|
125
|
+
test_command "certificate" "+list-certificates" "--start-time 1672502400000 --end-time 1704038400000" "获取证书列表"
|
|
126
|
+
test_command "certificate" "+list-categories" "" "获取证书分类"
|
|
127
|
+
echo ""
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
# ==================== Credit 模块 ====================
|
|
131
|
+
if should_test_module "credit"; then
|
|
132
|
+
echo -e "${YELLOW}[Credit 模块]${NC}"
|
|
133
|
+
test_command "credit" "+list-logs" "--start-time 1672502400000 --end-time 1704038400000" "获取学分日志"
|
|
134
|
+
echo ""
|
|
135
|
+
fi
|
|
136
|
+
|
|
137
|
+
# ==================== Point 模块 ====================
|
|
138
|
+
if should_test_module "point"; then
|
|
139
|
+
echo -e "${YELLOW}[Point 模块]${NC}"
|
|
140
|
+
test_command "point" "+list-logs" "--start-time 1672502400000 --end-time 1704038400000" "获取积分日志"
|
|
141
|
+
echo ""
|
|
142
|
+
fi
|
|
143
|
+
|
|
144
|
+
# ==================== Training 模块 ====================
|
|
145
|
+
if should_test_module "training"; then
|
|
146
|
+
echo -e "${YELLOW}[Training 模块]${NC}"
|
|
147
|
+
test_command "training" "+list-trainings" "--start-time 1672502400000 --end-time 1704038400000" "获取培训列表"
|
|
148
|
+
test_command "training" "+list-categories" "" "获取培训分类"
|
|
149
|
+
echo ""
|
|
150
|
+
fi
|
|
151
|
+
|
|
152
|
+
# ==================== Learning Map 模块 ====================
|
|
153
|
+
if should_test_module "learning-map"; then
|
|
154
|
+
echo -e "${YELLOW}[Learning Map 模块]${NC}"
|
|
155
|
+
test_command "learning-map" "+list-maps" "--start-time 1672502400000 --end-time 1704038400000" "获取学习地图列表"
|
|
156
|
+
test_command "learning-map" "+list-categories" "" "获取学习地图分类"
|
|
157
|
+
echo ""
|
|
158
|
+
fi
|
|
159
|
+
|
|
160
|
+
# ==================== News 模块 ====================
|
|
161
|
+
if should_test_module "news"; then
|
|
162
|
+
echo -e "${YELLOW}[News 模块]${NC}"
|
|
163
|
+
test_command "news" "+list-news" "" "获取新闻列表"
|
|
164
|
+
test_command "news" "+list-categories" "" "获取新闻分类"
|
|
165
|
+
echo ""
|
|
166
|
+
fi
|
|
167
|
+
|
|
168
|
+
# ==================== Clock 模块 ====================
|
|
169
|
+
if should_test_module "clock"; then
|
|
170
|
+
echo -e "${YELLOW}[Clock 模块]${NC}"
|
|
171
|
+
test_command "clock" "list-learnings" "--page 1 --page-size 10" "获取作业列表"
|
|
172
|
+
echo ""
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
# ==================== File 模块 ====================
|
|
176
|
+
if should_test_module "file"; then
|
|
177
|
+
echo -e "${YELLOW}[File 模块]${NC}"
|
|
178
|
+
test_command "file" "list-files" "" "获取素材库列表"
|
|
179
|
+
test_command "file" "list-categories" "" "获取素材库分类"
|
|
180
|
+
echo ""
|
|
181
|
+
fi
|
|
182
|
+
|
|
183
|
+
# ==================== 测试结果汇总 ====================
|
|
184
|
+
echo ""
|
|
185
|
+
echo -e "${BLUE}========================================${NC}"
|
|
186
|
+
echo -e "${BLUE} 测试结果汇总${NC}"
|
|
187
|
+
echo -e "${BLUE}========================================${NC}"
|
|
188
|
+
echo ""
|
|
189
|
+
echo -e "总测试数: ${BLUE}${TOTAL_TESTS}${NC}"
|
|
190
|
+
echo -e "通过: ${GREEN}${PASSED_TESTS}${NC}"
|
|
191
|
+
echo -e "失败: ${RED}${FAILED_TESTS}${NC}"
|
|
192
|
+
echo ""
|
|
193
|
+
|
|
194
|
+
if [ ${FAILED_TESTS} -gt 0 ]; then
|
|
195
|
+
echo -e "${RED}失败的命令:${NC}"
|
|
196
|
+
for cmd in "${FAILED_COMMANDS[@]}"; do
|
|
197
|
+
echo -e " ${RED}✗${NC} ./soke-cli $cmd"
|
|
198
|
+
done
|
|
199
|
+
echo ""
|
|
200
|
+
echo -e "${RED}测试失败! 请修复以上问题后再发布。${NC}"
|
|
201
|
+
exit 1
|
|
202
|
+
else
|
|
203
|
+
echo -e "${GREEN}========================================${NC}"
|
|
204
|
+
echo -e "${GREEN} 所有测试通过! ✓${NC}"
|
|
205
|
+
echo -e "${GREEN}========================================${NC}"
|
|
206
|
+
exit 0
|
|
207
|
+
fi
|
package/scripts/release.sh
CHANGED
|
@@ -75,14 +75,24 @@ check_tag() {
|
|
|
75
75
|
|
|
76
76
|
# 运行测试
|
|
77
77
|
run_tests() {
|
|
78
|
-
echo -e "${YELLOW}
|
|
78
|
+
echo -e "${YELLOW}运行单元测试...${NC}"
|
|
79
79
|
|
|
80
80
|
if ! go test ./...; then
|
|
81
|
-
echo -e "${RED}错误:
|
|
81
|
+
echo -e "${RED}错误: 单元测试失败${NC}"
|
|
82
82
|
exit 1
|
|
83
83
|
fi
|
|
84
84
|
|
|
85
|
-
echo -e "${GREEN}✓
|
|
85
|
+
echo -e "${GREEN}✓ 单元测试通过${NC}"
|
|
86
|
+
echo ""
|
|
87
|
+
|
|
88
|
+
echo -e "${YELLOW}运行端到端测试...${NC}"
|
|
89
|
+
|
|
90
|
+
if ! ./scripts/e2e-test.sh; then
|
|
91
|
+
echo -e "${RED}错误: 端到端测试失败${NC}"
|
|
92
|
+
exit 1
|
|
93
|
+
fi
|
|
94
|
+
|
|
95
|
+
echo -e "${GREEN}✓ 端到端测试通过${NC}"
|
|
86
96
|
echo ""
|
|
87
97
|
}
|
|
88
98
|
|