-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_validate_ext_test.go
122 lines (116 loc) · 2.34 KB
/
app_validate_ext_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package warg_test
import (
"testing"
"github.com/stretchr/testify/require"
"go.bbkane.com/warg"
"go.bbkane.com/warg/command"
"go.bbkane.com/warg/flag"
"go.bbkane.com/warg/section"
"go.bbkane.com/warg/value/scalar"
)
func TestApp_Validate(t *testing.T) {
tests := []struct {
name string
app warg.App // NOTE:
expectedErr bool
}{
{
name: "leafSection",
app: warg.New(
"newAppName",
section.New("Help for section"),
warg.SkipValidation(),
),
expectedErr: true,
},
// app.Validate should allow app names with dashes
{
name: "appNameWithDash",
app: warg.New(
"newAppName",
section.New("",
section.Command("com", "command for validation", command.DoNothing),
),
warg.SkipValidation(),
),
expectedErr: false,
},
{
name: "sectionNameWithDash",
app: warg.New(
"newAppName",
section.New("",
section.Section("-name", "",
section.Command("com", "command for validation", command.DoNothing),
),
),
warg.SkipValidation(),
),
expectedErr: true,
},
{
name: "commandNameWithDash",
app: warg.New(
"newAppName",
section.New("",
section.Section("name", "",
section.Command("-com", "starts with dash", command.DoNothing),
),
),
warg.SkipValidation(),
),
expectedErr: true,
},
{
name: "flagNameNoDash",
app: warg.New(
"newAppName",
section.New("",
section.Flag("f", "", nil),
section.Command("c", "", nil),
),
warg.SkipValidation(),
),
expectedErr: true,
},
{
name: "aliasNameNoDash",
app: warg.New(
"newAppName",
section.New("",
section.Flag("-f", "", scalar.Bool(),
flag.Alias("f"),
),
section.Command("c", "", nil),
),
warg.SkipValidation(),
),
expectedErr: true,
},
{
name: "flagNameAliasConflict",
app: warg.New(
"newAppName",
section.New("",
section.Flag("-f", "", scalar.Bool()),
section.Command("c", "", command.DoNothing,
command.Flag("--other", "", scalar.Bool(), flag.Alias("-f")),
),
),
warg.SkipValidation(),
),
expectedErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actualErr := tt.app.Validate()
if tt.expectedErr {
require.NotNil(t, actualErr)
return
} else {
require.Nil(t, actualErr)
}
})
}
}