* feat(windows): 增加原生服务安装包 * fix(windows): 收紧服务安装与升级流程 * fix(windows): 固定服务安装路径与语言资源 * fix(windows): 等待安装器进程完成 * fix(windows): 清理首次安装失败残留
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestParseServiceCommandAcceptsPublicActions(t *testing.T) {
|
|
for _, action := range []string{"start", "stop", "restart", "status"} {
|
|
t.Run(action, func(t *testing.T) {
|
|
command, err := parseServiceCommand([]string{action})
|
|
if err != nil {
|
|
t.Fatalf("parseServiceCommand(%q) error = %v", action, err)
|
|
}
|
|
if command.action != action {
|
|
t.Fatalf("action = %q, want %q", command.action, action)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseServiceCommandAcceptsHiddenInstallerActions(t *testing.T) {
|
|
for _, action := range []string{"install", "uninstall"} {
|
|
t.Run(action, func(t *testing.T) {
|
|
command, err := parseServiceCommand([]string{action})
|
|
if err != nil {
|
|
t.Fatalf("parseServiceCommand(%q) error = %v", action, err)
|
|
}
|
|
if command.action != action {
|
|
t.Fatalf("action = %q, want %q", command.action, action)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseServiceCommandAcceptsHiddenRunWithoutOptions(t *testing.T) {
|
|
command, err := parseServiceCommand([]string{"run"})
|
|
if err != nil {
|
|
t.Fatalf("parseServiceCommand(run) error = %v", err)
|
|
}
|
|
if command.action != "run" {
|
|
t.Fatalf("action = %q, want run", command.action)
|
|
}
|
|
}
|
|
|
|
func TestParseServiceCommandRejectsCustomServiceDirectories(t *testing.T) {
|
|
for _, action := range []string{"install", "run"} {
|
|
t.Run(action, func(t *testing.T) {
|
|
if _, err := parseServiceCommand([]string{
|
|
action,
|
|
"--config-dir", `C:\ProgramData\GPT-Load`,
|
|
"--data-dir", `C:\ProgramData\GPT-Load\data`,
|
|
}); err == nil {
|
|
t.Fatal("parseServiceCommand() error = nil, want fixed-directory enforcement")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseServiceCommandRejectsUnknownActionAndOptions(t *testing.T) {
|
|
for _, args := range [][]string{
|
|
{},
|
|
{"pause"},
|
|
{"status", "--data-dir", `C:\data`},
|
|
{"install", "--unknown", "value"},
|
|
} {
|
|
if _, err := parseServiceCommand(args); err == nil {
|
|
t.Fatalf("parseServiceCommand(%q) error = nil", args)
|
|
}
|
|
}
|
|
}
|