(t *testing.T)
| 43 | } |
| 44 | |
| 45 | func TestAPI_GetSuccess(t *testing.T) { |
| 46 | out, _ := iostreams.SetForTest(t) |
| 47 | cli, stop := newTestClient(t, func(w http.ResponseWriter, r *http.Request) { |
| 48 | if r.Method != http.MethodGet || r.URL.Path != "/api/v1/foo" { |
| 49 | t.Errorf("unexpected request: %s %s", r.Method, r.URL.Path) |
| 50 | } |
| 51 | w.Header().Set("Content-Type", "application/json") |
| 52 | _, _ = w.Write([]byte(`{"hello":"world"}`)) |
| 53 | }) |
| 54 | defer stop() |
| 55 | |
| 56 | if err := runAPI(context.Background(), &Options{}, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, cli, "GET", "/api/v1/foo", false); err != nil { |
| 57 | t.Fatalf("runAPI: %v", err) |
| 58 | } |
| 59 | got := out.String() |
| 60 | if !strings.Contains(got, `"hello":"world"`) { |
| 61 | t.Errorf("expected raw JSON body in stdout, got %q", got) |
| 62 | } |
| 63 | if !strings.HasSuffix(got, "\n") { |
| 64 | t.Errorf("expected trailing newline appended, got %q", got) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestAPI_GetSuccess_JSON(t *testing.T) { |
| 69 | out, _ := iostreams.SetForTest(t) |
nothing calls this directly
no test coverage detected