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

Function TestHandleResponse_JSONWithError

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

Source from the content-addressed store, hash-verified

261}
262
263func TestHandleResponse_JSONWithError(t *testing.T) {
264 body := []byte(`{"code":99991400,"msg":"invalid token"}`)
265 resp := newApiResp(body, map[string]string{"Content-Type": "application/json"})
266
267 var out bytes.Buffer
268 var errOut bytes.Buffer
269 err := HandleResponse(resp, ResponseOptions{
270 Out: &out,
271 ErrOut: &errOut,
272 FileIO: &localfileio.LocalFileIO{},
273 })
274 if err == nil {
275 t.Error("expected error for non-zero code")
276 }
277 if _, ok := errs.ProblemOf(err); !ok {
278 t.Fatalf("expected typed error, got %T: %v", err, err)
279 }
280 if strings.Contains(out.String(), `"ok": true`) || strings.Contains(out.String(), `"ok":true`) {
281 t.Fatalf("unexpected success envelope on error path: %s", out.String())
282 }
283}
284
285func TestHandleResponse_BinaryAutoSave(t *testing.T) {
286 dir := t.TempDir()

Callers

nothing calls this directly

Calls 6

ProblemOfFunction · 0.92
newApiRespFunction · 0.85
HandleResponseFunction · 0.85
ErrorMethod · 0.45
ContainsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected