-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
41 lines (37 loc) · 907 Bytes
/
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
package main
import (
"testing"
)
func TestProcessArgs(t *testing.T) {
cases := map[string]struct {
args []string
expectedArg string
wantErr bool
}{
"no argument": {
args: []string{"git-open"},
expectedArg: "",
},
"one argument": {
args: []string{"git-open", "LICENSE"},
expectedArg: "LICENSE",
},
"two arguments": {
args: []string{"git-open", "LICENSE", "README.md"},
expectedArg: "",
wantErr: true,
},
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
arg, err := processArgs(c.args)
if err != nil && !c.wantErr {
t.Fatalf("unexpected error:\n\t(GOT): %#v\n\t(WNT): nil", err)
} else if err == nil && c.wantErr {
t.Fatalf("expected error:\n\t(GOT): nil\n")
} else if arg != c.expectedArg {
t.Fatalf("unexpected arg:\n\t(GOT): %#v\n\t(WNT): %#v", arg, c.expectedArg)
}
})
}
}