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

Function TestParseJSONResponse

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

Source from the content-addressed store, hash-verified

57}
58
59func TestParseJSONResponse(t *testing.T) {
60 body := []byte(`{"code":0,"msg":"ok","data":{"id":"123"}}`)
61 resp := newApiResp(body, map[string]string{"Content-Type": "application/json"})
62 result, err := ParseJSONResponse(resp)
63 if err != nil {
64 t.Fatalf("ParseJSONResponse failed: %v", err)
65 }
66 m, ok := result.(map[string]interface{})
67 if !ok {
68 t.Fatal("expected map result")
69 }
70 if m["msg"] != "ok" {
71 t.Errorf("expected msg=ok, got %v", m["msg"])
72 }
73}
74
75func TestParseJSONResponse_Invalid(t *testing.T) {
76 resp := newApiResp([]byte(`not json`), map[string]string{"Content-Type": "application/json"})

Callers

nothing calls this directly

Calls 2

newApiRespFunction · 0.85
ParseJSONResponseFunction · 0.85

Tested by

no test coverage detected