2015-06-01 13:25:51 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"reflect"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-09-14 20:13:52 +00:00
|
|
|
func TestMeta_FlagSet(t *testing.T) {
|
2015-06-01 13:25:51 +00:00
|
|
|
cases := []struct {
|
|
|
|
Flags FlagSetFlags
|
|
|
|
Expected []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
FlagSetNone,
|
|
|
|
[]string{},
|
|
|
|
},
|
|
|
|
{
|
2015-09-14 20:13:52 +00:00
|
|
|
FlagSetClient,
|
2016-05-25 01:53:46 +00:00
|
|
|
[]string{"address", "no-color"},
|
2015-06-01 13:25:51 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, tc := range cases {
|
|
|
|
var m Meta
|
|
|
|
fs := m.FlagSet("foo", tc.Flags)
|
|
|
|
|
|
|
|
actual := make([]string, 0, 0)
|
|
|
|
fs.VisitAll(func(f *flag.Flag) {
|
|
|
|
actual = append(actual, f.Name)
|
|
|
|
})
|
|
|
|
sort.Strings(actual)
|
|
|
|
sort.Strings(tc.Expected)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(actual, tc.Expected) {
|
|
|
|
t.Fatalf("%d: flags: %#v\n\nExpected: %#v\nGot: %#v",
|
|
|
|
i, tc.Flags, tc.Expected, actual)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|