Add unit test for GenericFlag Destination parsing
The test checks if Destination provided in GenericFlag is being set as expected.
This commit is contained in:
parent
a2541e0fe4
commit
c472192257
47
flag_test.go
47
flag_test.go
@ -2724,6 +2724,53 @@ func TestParseGeneric(t *testing.T) {
|
||||
}).Run([]string{"run", "-s", "10,20"})
|
||||
}
|
||||
|
||||
type genericType struct {
|
||||
s []string
|
||||
}
|
||||
|
||||
func (g *genericType) Set(value string) error {
|
||||
g.s = strings.Split(value, "-")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *genericType) String() string {
|
||||
return strings.Join(g.s, "-")
|
||||
}
|
||||
|
||||
func TestParseDestinationGeneric(t *testing.T) {
|
||||
expectedString := "abc1-123d"
|
||||
expectedGeneric := &genericType{[]string{"abc1", "123d"}}
|
||||
dest := &genericType{}
|
||||
|
||||
_ = (&App{
|
||||
Flags: []Flag{
|
||||
&GenericFlag{
|
||||
Name: "dest",
|
||||
Destination: dest,
|
||||
},
|
||||
},
|
||||
Action: func(ctx *Context) error {
|
||||
|
||||
if !reflect.DeepEqual(dest, expectedGeneric) {
|
||||
t.Errorf(
|
||||
"expected destination generic: %+v, actual: %+v",
|
||||
expectedGeneric,
|
||||
dest,
|
||||
)
|
||||
}
|
||||
|
||||
if dest.String() != expectedString {
|
||||
t.Errorf(
|
||||
"expected destination string: %s, actual: %s",
|
||||
expectedString,
|
||||
dest.String(),
|
||||
)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}).Run([]string{"run", "--dest", expectedString})
|
||||
}
|
||||
|
||||
func TestParseGenericFromEnv(t *testing.T) {
|
||||
defer resetEnv(os.Environ())
|
||||
os.Clearenv()
|
||||
|
Loading…
Reference in New Issue
Block a user