-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_check_options_test.go
48 lines (39 loc) · 1.24 KB
/
post_check_options_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
package cliz
import (
"context"
"testing"
"github.com/hakadoriya/z.go/testingz/requirez"
)
func TestCommand_postCheckOptions(t *testing.T) {
t.Parallel()
t.Run("error,ErrDuplicateOption,Name", func(t *testing.T) {
t.Parallel()
c := newTestCommand()
for _, subcmd := range c.SubCommands {
subcmd.Options = append(subcmd.Options, &StringOption{Name: "foo"})
}
ctx := context.Background()
_, err := c.parse(ctx, []string{"main-cli", "sub-cmd"})
requirez.ErrorIs(t, err, ErrDuplicateOption)
})
t.Run("error,ErrDuplicateOption,Aliases", func(t *testing.T) {
t.Parallel()
c := newTestCommand()
for _, subcmd := range c.SubCommands {
subcmd.Options = append(subcmd.Options, &StringOption{Name: "b2", Aliases: []string{"b"}})
}
ctx := context.Background()
_, err := c.parse(ctx, []string{"main-cli", "sub-cmd"})
requirez.ErrorIs(t, err, ErrDuplicateOption)
})
t.Run("error,ErrOptionRequired", func(t *testing.T) {
t.Parallel()
c := newTestCommand()
for _, subcmd := range c.SubCommands {
subcmd.Options = append(subcmd.Options, &StringOption{Name: "required", Required: true})
}
ctx := context.Background()
_, err := c.parse(ctx, []string{"main-cli", "sub-cmd"})
requirez.ErrorIs(t, err, ErrOptionRequired)
})
}