MCPcopy Create free account
hub / github.com/bytebase/bytebase / TestApiRequest_RawMessage

Function TestApiRequest_RawMessage

backend/api/mcp/tool_http_test.go:62–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

60}
61
62func TestApiRequest_RawMessage(t *testing.T) {
63 const payload = `{"id":12345,"count":9999999999}`
64 s := newTestServerWithMock(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
65 w.WriteHeader(http.StatusOK)
66 fmt.Fprint(w, payload)
67 }))
68
69 ctx := context.Background()
70 resp, err := s.apiRequest(ctx, "/api/test", nil)
71 require.NoError(t, err)
72 require.Equal(t, http.StatusOK, resp.Status)
73
74 // Verify raw JSON is preserved.
75 require.JSONEq(t, payload, string(resp.Body))
76
77 // Decode into typed struct with int64 fields to verify integers are preserved.
78 type result struct {
79 ID int64 `json:"id"`
80 Count int64 `json:"count"`
81 }
82 var r result
83 err = json.Unmarshal(resp.Body, &r)
84 require.NoError(t, err)
85 require.Equal(t, int64(12345), r.ID)
86 require.Equal(t, int64(9999999999), r.Count)
87}
88
89// testContext returns a context with a test workspace ID.
90func testContext() context.Context {

Callers

nothing calls this directly

Calls 4

newTestServerWithMockFunction · 0.85
apiRequestMethod · 0.80
UnmarshalMethod · 0.80
EqualMethod · 0.65

Tested by

no test coverage detected