-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain_test.go
More file actions
50 lines (45 loc) · 1.09 KB
/
main_test.go
File metadata and controls
50 lines (45 loc) · 1.09 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
package main
import (
"strings"
"testing"
)
func TestRootCommand_URLValidation(t *testing.T) {
tests := []struct {
name string
coderURL string
wantError string
}{
{
name: "missing scheme",
coderURL: "coder.example.com",
wantError: "CODER_URL must include http:// or https:// scheme",
},
{
name: "empty scheme with path",
coderURL: "//coder.example.com",
wantError: "CODER_URL must include http:// or https:// scheme",
},
{
name: "ftp scheme",
coderURL: "ftp://coder.example.com",
wantError: "CODER_URL must include http:// or https:// scheme",
},
{
name: "empty URL",
coderURL: "",
wantError: "--coder-url is required",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := root()
inv := cmd.Invoke("--coder-url", tt.coderURL)
err := inv.Run()
if err == nil {
t.Errorf("expected error containing %q, got nil", tt.wantError)
} else if !strings.Contains(err.Error(), tt.wantError) {
t.Errorf("expected error containing %q, got %q", tt.wantError, err.Error())
}
})
}
}