-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
52 lines (43 loc) · 1.19 KB
/
main_test.go
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
package main
import (
"strings"
"testing"
)
func TestParseCommandLine(t *testing.T) {
tests := []struct {
args []string
wantAddr string
wantDir string
wantHelp bool
wantExit int
}{
{args: []string{"-h"}, wantHelp: true, wantExit: 0},
{args: []string{"a", "b", "c"}, wantHelp: true, wantExit: 1},
{args: nil, wantAddr: defaultHostPort, wantDir: "."},
{args: []string{":80"}, wantAddr: ":80", wantDir: "."},
{args: []string{"0.0.0.0:4567", "/foo/bar"}, wantAddr: "0.0.0.0:4567", wantDir: "/foo/bar"},
}
for _, tt := range tests {
args := []string{"serve"}
for _, a := range tt.args {
args = append(args, `"`+a+`"`)
}
cli := strings.Join(args, " ")
t.Run(cli, func(t *testing.T) {
gotRoot, gotAddr, gotHelp, gotExit := parseCommandLine(tt.args)
_ = gotExit
if gotHelp != tt.wantHelp {
t.Fatalf("parseCommandLine(`%v`) gotHelp = %v, want %v", cli, gotHelp, tt.wantHelp)
}
if gotHelp {
return
}
if gotAddr != tt.wantAddr {
t.Fatalf("parseCommandLine(`%v`) gotAddr = %v, want %v", cli, gotAddr, tt.wantAddr)
}
if gotRoot != tt.wantDir {
t.Fatalf("parseCommandLine(`%v`) gotRoot = %v, want %v", cli, gotRoot, tt.wantDir)
}
})
}
}