-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcmd_test.go
55 lines (48 loc) · 1.06 KB
/
cmd_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
53
54
55
package cmd_test
import (
"errors"
"flag"
"testing"
"github.com/hamba/cmd/v2"
"github.com/stretchr/testify/assert"
"github.com/urfave/cli/v2"
)
func TestSplit(t *testing.T) {
tests := []struct {
name string
input []string
want [][2]string
wantErr error
}{
{
name: "valid input",
input: []string{"a=b", "c=d"},
want: [][2]string{{"a", "b"}, {"c", "d"}},
wantErr: nil,
},
{
name: "invalid input",
input: []string{"a"},
wantErr: errors.New("string \"a\" does not contain \"=\""),
},
{
name: "mixed invalid input",
input: []string{"a=b", "c"},
wantErr: errors.New("string \"c\" does not contain \"=\""),
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
res, err := cmd.Split(test.input, "=")
assert.Equal(t, res, test.want)
assert.Equal(t, err, test.wantErr)
})
}
}
func newTestContext() (*cli.Context, *flag.FlagSet) {
fs := flag.NewFlagSet("test", flag.ContinueOnError)
c := cli.NewContext(&cli.App{}, fs, nil)
return c, fs
}