TestAPI_InputFile verifies --input reads the request body from disk.
(t *testing.T)
| 132 | |
| 133 | // TestAPI_InputFile verifies --input <file> reads the request body from disk. |
| 134 | func TestAPI_InputFile(t *testing.T) { |
| 135 | _, _ = iostreams.SetForTest(t) |
| 136 | tmp := filepath.Join(t.TempDir(), "body.json") |
| 137 | payload := `{"k":"from-file"}` |
| 138 | if err := os.WriteFile(tmp, []byte(payload), 0o600); err != nil { |
| 139 | t.Fatalf("write temp: %v", err) |
| 140 | } |
| 141 | var seenBody []byte |
| 142 | cli, stop := newTestClient(t, func(w http.ResponseWriter, r *http.Request) { |
| 143 | seenBody, _ = io.ReadAll(r.Body) |
| 144 | _, _ = w.Write([]byte(`{}`)) |
| 145 | }) |
| 146 | defer stop() |
| 147 | |
| 148 | opts := &Options{Input: tmp} |
| 149 | if err := runAPI(context.Background(), opts, &cmdutil.FormatOptions{Mode: cmdutil.FormatText}, cli, "POST", "/api/v1/x", false); err != nil { |
| 150 | t.Fatalf("runAPI: %v", err) |
| 151 | } |
| 152 | if string(seenBody) != payload { |
| 153 | t.Errorf("body from --input: got %q, want %q", seenBody, payload) |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | // TestAPI_InputDash_Stdin verifies the "--input -" form: the payload comes |
| 158 | // from opts.StdinReader (production-default iostreams.IO.In). |
nothing calls this directly
no test coverage detected