(t *testing.T)
| 57 | } |
| 58 | |
| 59 | func 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 | |
| 75 | func TestParseJSONResponse_Invalid(t *testing.T) { |
| 76 | resp := newApiResp([]byte(`not json`), map[string]string{"Content-Type": "application/json"}) |
nothing calls this directly
no test coverage detected