(t *testing.T)
| 16 | } |
| 17 | |
| 18 | func TestRunListCmd(t *testing.T) { |
| 19 | testCases := map[string]struct { |
| 20 | dataType string |
| 21 | url string |
| 22 | expectedErr interface{} |
| 23 | }{ |
| 24 | "Countries": {"countries", "/analytics/dns/countries", nil}, |
| 25 | "Cities": {"cities", "/analytics/dns/city", nil}, |
| 26 | "Wrong type": {"country", "/analytics/dns/country", "no data with type 'country'"}, |
| 27 | } |
| 28 | |
| 29 | for name, tc := range testCases { |
| 30 | t.Run(name, func(t *testing.T) { |
| 31 | tr := &recordingTransport{} |
| 32 | c, err := newTestPerfopsClient(tr) |
| 33 | if err != nil { |
| 34 | t.Fatalf("unexpected error %v", err) |
| 35 | } |
| 36 | |
| 37 | err = runListCmd(c, tc.dataType) |
| 38 | |
| 39 | if tc.expectedErr != nil { |
| 40 | if tc.expectedErr != err.Error() { |
| 41 | t.Fatalf("expected %v error; got %v", tc.expectedErr, err) |
| 42 | } |
| 43 | |
| 44 | // No reason to continue if we check for error case |
| 45 | return |
| 46 | } |
| 47 | |
| 48 | if got, exp := tr.req.URL.Path, tc.url; got != exp { |
| 49 | t.Fatalf("expected %v; got %v", exp, got) |
| 50 | } |
| 51 | }) |
| 52 | } |
| 53 | } |
nothing calls this directly
no test coverage detected