(t *testing.T)
| 306 | } |
| 307 | |
| 308 | func TestHandleResponse_BinaryWithOutput(t *testing.T) { |
| 309 | dir := t.TempDir() |
| 310 | origWd, _ := os.Getwd() |
| 311 | os.Chdir(dir) |
| 312 | defer os.Chdir(origWd) |
| 313 | |
| 314 | resp := newApiResp([]byte("PNG DATA"), map[string]string{"Content-Type": "image/png"}) |
| 315 | |
| 316 | var out bytes.Buffer |
| 317 | var errOut bytes.Buffer |
| 318 | err := HandleResponse(resp, ResponseOptions{ |
| 319 | OutputPath: "out.png", |
| 320 | Out: &out, |
| 321 | ErrOut: &errOut, |
| 322 | FileIO: &localfileio.LocalFileIO{}, |
| 323 | }) |
| 324 | if err != nil { |
| 325 | t.Fatalf("HandleResponse with output path failed: %v", err) |
| 326 | } |
| 327 | data, _ := os.ReadFile("out.png") |
| 328 | if string(data) != "PNG DATA" { |
| 329 | t.Errorf("expected saved PNG DATA, got: %s", data) |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | func TestHandleResponse_NonJSONError_404(t *testing.T) { |
| 334 | resp := newApiRespWithStatus(404, []byte("404 page not found"), map[string]string{"Content-Type": "text/plain"}) |
nothing calls this directly
no test coverage detected