-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_config_validation_test.go
More file actions
53 lines (48 loc) · 1.49 KB
/
command_config_validation_test.go
File metadata and controls
53 lines (48 loc) · 1.49 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
51
52
53
package cli
import (
"testing"
"github.com/broothie/option"
"github.com/stretchr/testify/assert"
)
func TestCommand_config_validations(t *testing.T) {
type TestCase struct {
commandOptions option.Options[*Command]
expectedError string
}
testCases := map[string]TestCase{
"validateNoDuplicateFlags": {
commandOptions: option.NewOptions(
AddFlag("some-flag", "some flag"),
AddFlag("some-flag", "some flag"),
),
expectedError: `invalid command "test": duplicate flag "some-flag"`,
},
"validateNoDuplicateArguments": {
commandOptions: option.NewOptions(
AddArg("some-arg", "some arg"),
AddArg("some-arg", "some arg"),
),
expectedError: `invalid command "test": duplicate argument "some-arg"`,
},
"validateNoDuplicateSubCommands": {
commandOptions: option.NewOptions(
AddSubCmd("some-sub-command", "some sub-command"),
AddSubCmd("some-sub-command", "some sub-command"),
),
expectedError: `invalid command "test": duplicate sub-command "some-sub-command"`,
},
"validateEitherCommandsOrArguments": {
commandOptions: option.NewOptions(
AddArg("some-arg", "some arg"),
AddSubCmd("some-sub-command", "some sub-command"),
),
expectedError: `invalid command "test": cannot have both sub-commands and arguments`,
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
_, err := NewCommand("test", "test command", testCase.commandOptions...)
assert.EqualError(t, err, testCase.expectedError)
})
}
}