MCPcopy
hub / github.com/larksuite/cli / TestHandleResponse_BinaryWithOutput

Function TestHandleResponse_BinaryWithOutput

internal/client/response_test.go:308–331  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

306}
307
308func 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
333func TestHandleResponse_NonJSONError_404(t *testing.T) {
334 resp := newApiRespWithStatus(404, []byte("404 page not found"), map[string]string{"Content-Type": "text/plain"})

Callers

nothing calls this directly

Calls 4

newApiRespFunction · 0.85
HandleResponseFunction · 0.85
GetwdMethod · 0.65
ReadFileMethod · 0.65

Tested by

no test coverage detected