refactor: use nginx -s reload instead of systemd
- doc: add comment
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
"yms-daemon/internal/daemonapi"
|
||||
)
|
||||
|
||||
// TestParseUpdateArgsAcceptsBackendAndResolvesFile 验证 update 子命令能接受 backend 服务与 -f 文件参数,
|
||||
// 并正确解析出 repack-zip 输入类型与文件路径。
|
||||
func TestParseUpdateArgsAcceptsBackendAndResolvesFile(t *testing.T) {
|
||||
file := filepath.Join(t.TempDir(), "package.zip")
|
||||
if err := os.WriteFile(file, []byte("zip"), 0o600); err != nil {
|
||||
@@ -25,6 +27,8 @@ func TestParseUpdateArgsAcceptsBackendAndResolvesFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseUpdateArgsAcceptsDirectNativeJAR 验证 update 子命令能接受 --native-jar 参数,
|
||||
// 并正确解析出 native-jar 输入类型与文件路径。
|
||||
func TestParseUpdateArgsAcceptsDirectNativeJAR(t *testing.T) {
|
||||
file := filepath.Join(t.TempDir(), "glory-soft-yms.jar")
|
||||
if err := os.WriteFile(file, []byte("jar"), 0o600); err != nil {
|
||||
@@ -39,6 +43,8 @@ func TestParseUpdateArgsAcceptsDirectNativeJAR(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseUpdateArgsAcceptsContainerImage 验证 update 子命令能接受 --container-image 参数,
|
||||
// 并正确解析出 container-image 输入类型与镜像引用。
|
||||
func TestParseUpdateArgsAcceptsContainerImage(t *testing.T) {
|
||||
imageReference := "harbor.ymswell.asia/ymswell/glory-ymswell:20260813-184902-a37bf50d-v1.1.8.1"
|
||||
request, err := parseUpdateArgs([]string{"--service", "backend", "--container-image", imageReference}, &bytes.Buffer{})
|
||||
@@ -50,6 +56,8 @@ func TestParseUpdateArgsAcceptsContainerImage(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseUpdateArgsControlsContainerStartupLogs 验证 --no-start-log 能关闭容器启动日志,
|
||||
// 且默认情况下启动日志处于开启状态。
|
||||
func TestParseUpdateArgsControlsContainerStartupLogs(t *testing.T) {
|
||||
imageReference := "harbor.ymswell.asia/ymswell/glory-ymswell:20260813-184902-a37bf50d-v1.1.8.1"
|
||||
request, err := parseUpdateArgs([]string{"--service", "backend", "--container-image", imageReference, "--no-start-log"}, &bytes.Buffer{})
|
||||
@@ -68,6 +76,8 @@ func TestParseUpdateArgsControlsContainerStartupLogs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseUpdateArgsRejectsNativeJARAndContainerImageTogether 验证同时提供 --native-jar 与
|
||||
// --container-image 时会被拒绝,并返回互斥错误提示。
|
||||
func TestParseUpdateArgsRejectsNativeJARAndContainerImageTogether(t *testing.T) {
|
||||
jarPath := filepath.Join(t.TempDir(), "glory-soft-yms.jar")
|
||||
arguments := []string{
|
||||
@@ -81,6 +91,7 @@ func TestParseUpdateArgsRejectsNativeJARAndContainerImageTogether(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseUpdateArgsAcceptsQuite 验证 --quite 选项能被解析并保留到参数结果中。
|
||||
func TestParseUpdateArgsAcceptsQuite(t *testing.T) {
|
||||
file := filepath.Join(t.TempDir(), "glory-soft-yms.jar")
|
||||
if err := os.WriteFile(file, []byte("jar"), 0o600); err != nil {
|
||||
@@ -95,6 +106,7 @@ func TestParseUpdateArgsAcceptsQuite(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestWriteUpdateProgress 验证进度事件的格式化输出:状态字段左对齐占 14 列后紧跟消息。
|
||||
func TestWriteUpdateProgress(t *testing.T) {
|
||||
var output bytes.Buffer
|
||||
writeUpdateProgress(&output, daemonapi.Response{State: "STARTING", Message: "Starting backend"})
|
||||
@@ -103,6 +115,7 @@ func TestWriteUpdateProgress(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseRestartArgs 验证 restart 子命令能接受 backend 服务与 --quite 选项。
|
||||
func TestParseRestartArgs(t *testing.T) {
|
||||
request, err := parseRestartArgs([]string{"--service", "backend", "--quite"}, &bytes.Buffer{})
|
||||
if err != nil {
|
||||
@@ -113,6 +126,8 @@ func TestParseRestartArgs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseRestartArgsRejectsUnsupportedInput 验证 restart 子命令对缺失服务、非 backend 服务
|
||||
// 以及位置参数等非法输入均会拒绝。
|
||||
func TestParseRestartArgsRejectsUnsupportedInput(t *testing.T) {
|
||||
for name, arguments := range map[string][]string{
|
||||
"missing service": nil,
|
||||
@@ -127,6 +142,8 @@ func TestParseRestartArgsRejectsUnsupportedInput(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseUpdateArgsRejectsIncompleteOrUnsupportedInput 验证 update 子命令对缺失服务、缺失文件、
|
||||
// 非 backend 服务、位置参数以及多个互斥输入等非法组合均会拒绝。
|
||||
func TestParseUpdateArgsRejectsIncompleteOrUnsupportedInput(t *testing.T) {
|
||||
for name, arguments := range map[string][]string{
|
||||
"missing service": {"-f", "/tmp/package.zip"},
|
||||
@@ -144,6 +161,7 @@ func TestParseUpdateArgsRejectsIncompleteOrUnsupportedInput(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestRunPrintsUsageWithoutCommand 验证不带任何子命令调用 run 时返回退出码 2 并向 stderr 输出用法。
|
||||
func TestRunPrintsUsageWithoutCommand(t *testing.T) {
|
||||
var stderr bytes.Buffer
|
||||
if exitCode := run(context.Background(), nil, &bytes.Buffer{}, &stderr); exitCode != 2 {
|
||||
|
||||
Reference in New Issue
Block a user