-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_cli_test.go
More file actions
177 lines (160 loc) · 6.07 KB
/
Copy pathmodule_cli_test.go
File metadata and controls
177 lines (160 loc) · 6.07 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package main
import (
"bytes"
"os"
"path/filepath"
"strings"
"testing"
)
func mustMkdir(t *testing.T, baseDir, name string) {
t.Helper()
if err := os.Mkdir(filepath.Join(baseDir, name), 0755); err != nil {
t.Fatalf("creating %s: %v", name, err)
}
}
func TestParseModuleCommandInstallLatest(t *testing.T) {
cmd, handled, err := parseModuleCommand([]string{"--module", "owlcms", "--install", "latest"})
if err != nil {
t.Fatalf("parseModuleCommand returned error: %v", err)
}
if !handled {
t.Fatal("expected command to be handled")
}
if cmd.Module != "owlcms" || cmd.Action != "install" || cmd.InstallVersion != "latest" {
t.Fatalf("unexpected command: %#v", cmd)
}
}
func TestParseModuleCommandInstallDefaultsToLatest(t *testing.T) {
cmd, handled, err := parseModuleCommand([]string{"--module", "tracker", "--install"})
if err != nil {
t.Fatalf("parseModuleCommand returned error: %v", err)
}
if !handled {
t.Fatal("expected command to be handled")
}
if cmd.Module != "tracker" || cmd.Action != "install" || cmd.InstallVersion != "latest" {
t.Fatalf("unexpected command: %#v", cmd)
}
}
func TestParseModuleCommandSeparatesLocalAndRemoteLatest(t *testing.T) {
cmd, handled, err := parseModuleCommand([]string{"--module", "owlcms", "--version", "latest", "--update-to", "latest"})
if err != nil {
t.Fatalf("parseModuleCommand returned error: %v", err)
}
if !handled {
t.Fatal("expected command to be handled")
}
if cmd.Module != "owlcms" || cmd.Action != "update" || cmd.Version != "latest" || cmd.UpdateTo != "latest" {
t.Fatalf("unexpected command: %#v", cmd)
}
}
func TestParseModuleCommandLocalTrackerDefaultPort(t *testing.T) {
cmd, handled, err := parseModuleCommand([]string{"--module", "owlcms", "--launch", "--local-tracker"})
if err != nil {
t.Fatalf("parseModuleCommand returned error: %v", err)
}
if !handled {
t.Fatal("expected command to be handled")
}
if cmd.Action != "launch" || cmd.LocalTrackerPort != "8096" {
t.Fatalf("unexpected command: %#v", cmd)
}
}
func TestParseModuleCommandBackgroundAliasEnablesDaemonMode(t *testing.T) {
cmd, handled, err := parseModuleCommand([]string{"--module", "owlcms", "--launch", "--background"})
if err != nil {
t.Fatalf("parseModuleCommand returned error: %v", err)
}
if !handled {
t.Fatal("expected command to be handled")
}
if cmd.Action != "launch" || !cmd.DaemonMode {
t.Fatalf("unexpected command: %#v", cmd)
}
}
func TestParseModuleCommandInstallZip(t *testing.T) {
cmd, handled, err := parseModuleCommand([]string{"--module", "owlcms", "--install-zip", "C:/Downloads/owlcms_66.0.0.zip"})
if err != nil {
t.Fatalf("parseModuleCommand returned error: %v", err)
}
if !handled {
t.Fatal("expected command to be handled")
}
if cmd.Action != "install-zip" || cmd.InstallZipPath != "C:/Downloads/owlcms_66.0.0.zip" {
t.Fatalf("unexpected command: %#v", cmd)
}
}
func TestParseModuleCommandCreateZip(t *testing.T) {
cmd, handled, err := parseModuleCommand([]string{"--module", "tracker", "--create-zip", "C:/Backups/tracker.zip", "--version", "3.4.0"})
if err != nil {
t.Fatalf("parseModuleCommand returned error: %v", err)
}
if !handled {
t.Fatal("expected command to be handled")
}
if cmd.Action != "create-zip" || cmd.CreateZipPath != "C:/Backups/tracker.zip" || cmd.Version != "3.4.0" {
t.Fatalf("unexpected command: %#v", cmd)
}
}
func TestParseModuleCommandRejectsLegacyOwlcmsFlag(t *testing.T) {
_, handled, err := parseModuleCommand([]string{"--owlcms", "latest"})
if !handled {
t.Fatal("expected legacy flag to be handled as a command-line error")
}
if err == nil || !strings.Contains(err.Error(), "not supported") {
t.Fatalf("expected unsupported legacy flag error, got %v", err)
}
}
func TestParseModuleCommandRejectsLocalTrackerForTrackerModule(t *testing.T) {
_, handled, err := parseModuleCommand([]string{"--module", "tracker", "--launch", "--local-tracker"})
if !handled {
t.Fatal("expected command to be handled")
}
if err == nil || !strings.Contains(err.Error(), "--module owlcms") {
t.Fatalf("expected local-tracker module error, got %v", err)
}
}
func TestExecuteModuleDuplicateRequiresFromVersion(t *testing.T) {
err := executeModuleCommand(moduleCLICommand{Module: "owlcms", Action: "duplicate", DuplicateName: "copy"}, &bytes.Buffer{})
if err == nil || !strings.Contains(err.Error(), "--from-version") {
t.Fatalf("expected from-version error, got %v", err)
}
}
func TestModuleCommandRequiresExclusiveControlPanel(t *testing.T) {
if moduleCommandRequiresExclusiveControlPanel(moduleCLICommand{Module: "owlcms", Action: "list"}) {
t.Fatal("expected list command to be allowed while a control panel is running")
}
if moduleCommandRequiresExclusiveControlPanel(moduleCLICommand{Module: "owlcms", Action: "stop"}) {
t.Fatal("expected stop command to be allowed while a control panel is running")
}
if moduleCommandRequiresExclusiveControlPanel(moduleCLICommand{Module: "owlcms", Action: "launch"}) {
t.Fatal("expected launch command to be allowed while a control panel is running")
}
if !moduleCommandRequiresExclusiveControlPanel(moduleCLICommand{Module: "tracker", Action: "update"}) {
t.Fatal("expected update command to require exclusive control panel ownership")
}
}
func TestResolveLocalVersionSelectorPreviousUsesPenultimateInstalledVersion(t *testing.T) {
base := t.TempDir()
mustMkdir(t, base, "65.0.0")
mustMkdir(t, base, "64.0.0")
mustMkdir(t, base, "63.0.0")
version, err := resolveLocalVersionSelector("owlcms", "previous", []string{"65.0.0", "64.0.0", "63.0.0"}, base)
if err != nil {
t.Fatalf("resolveLocalVersionSelector returned error: %v", err)
}
if version != "64.0.0" {
t.Fatalf("expected previous=64.0.0, got %q", version)
}
}
func TestResolveLocalVersionSelectorAllowsSpecificNonSemverDirectory(t *testing.T) {
base := t.TempDir()
mustMkdir(t, base, "duplicate-65.0.0")
version, err := resolveLocalVersionSelector("owlcms", "duplicate-65.0.0", nil, base)
if err != nil {
t.Fatalf("resolveLocalVersionSelector returned error: %v", err)
}
if version != "duplicate-65.0.0" {
t.Fatalf("expected exact duplicate directory, got %q", version)
}
}