(t *testing.T)
| 21 | ) |
| 22 | |
| 23 | func TestInitPingCmd(t *testing.T) { |
| 24 | testCases := map[string]struct { |
| 25 | args []string |
| 26 | gotexp func() (interface{}, interface{}) |
| 27 | }{ |
| 28 | // Common flags |
| 29 | "from": {[]string{"--from", "Europe"}, func() (interface{}, interface{}) { return from, "Europe" }}, |
| 30 | "nodeid": {[]string{"--nodeid", "1,2,3"}, func() (interface{}, interface{}) { return nodeIDs, []int{1, 2, 3} }}, |
| 31 | "json": {[]string{"--json"}, func() (interface{}, interface{}) { return outputJSON, true }}, |
| 32 | |
| 33 | "limit": {[]string{"--limit", "23"}, func() (interface{}, interface{}) { return pingLimit, 23 }}, |
| 34 | } |
| 35 | parent := &cobra.Command{} |
| 36 | for name, tc := range testCases { |
| 37 | t.Run(name, func(t *testing.T) { |
| 38 | pingCmd.ResetFlags() |
| 39 | initPingCmd(parent) |
| 40 | if err := pingCmd.ParseFlags(tc.args); err != nil { |
| 41 | t.Fatalf("exepected nil; got %v", err) |
| 42 | } |
| 43 | flags := pingCmd.Flags() |
| 44 | f := flags.Lookup(name) |
| 45 | if f == nil { |
| 46 | t.Fatal("expected flag; got nil") |
| 47 | } |
| 48 | |
| 49 | got, exp := tc.gotexp() |
| 50 | if reflect.DeepEqual(got, exp) == false { |
| 51 | t.Fatalf("expected %v; got %v", exp, got) |
| 52 | } |
| 53 | }) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | func TestRunPing(t *testing.T) { |
| 58 | testCases := map[string]struct { |
nothing calls this directly
no test coverage detected