(t *testing.T)
| 106 | } |
| 107 | |
| 108 | func TestAPI_PostWithStdinInput(t *testing.T) { |
| 109 | _, _ = iostreams.SetForTest(t) |
| 110 | var seenBody []byte |
| 111 | var seenMethod, seenPath string |
| 112 | cli, stop := newTestClient(t, func(w http.ResponseWriter, r *http.Request) { |
| 113 | seenMethod = r.Method |
| 114 | seenPath = r.URL.Path |
| 115 | seenBody, _ = io.ReadAll(r.Body) |
| 116 | w.Header().Set("Content-Type", "application/json") |
| 117 | _, _ = w.Write([]byte(`{"id":"new"}`)) |
| 118 | }) |
| 119 | defer stop() |
| 120 | |
| 121 | opts := &Options{Input: "-", StdinReader: strings.NewReader(`{"name":"foo"}`)} |
| 122 | if err := runAPI(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, cli, "POST", "/api/v1/things", false); err != nil { |
| 123 | t.Fatalf("runAPI: %v", err) |
| 124 | } |
| 125 | if seenMethod != http.MethodPost || seenPath != "/api/v1/things" { |
| 126 | t.Errorf("server saw %s %s, want POST /api/v1/things", seenMethod, seenPath) |
| 127 | } |
| 128 | if string(seenBody) != `{"name":"foo"}` { |
| 129 | t.Errorf("server received body %q, want %q", seenBody, `{"name":"foo"}`) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // TestAPI_InputFile verifies --input <file> reads the request body from disk. |
| 134 | func TestAPI_InputFile(t *testing.T) { |
nothing calls this directly
no test coverage detected