MCPcopy
hub / github.com/github/github-mcp-server / mockResponse

Function mockResponse

pkg/github/helper_test.go:296–312  ·  view source on GitHub ↗

mockResponse is a helper function to create a mock HTTP response handler that returns a specified status code and marshaled body.

(t *testing.T, code int, body any)

Source from the content-addressed store, hash-verified

294// mockResponse is a helper function to create a mock HTTP response handler
295// that returns a specified status code and marshaled body.
296func mockResponse(t *testing.T, code int, body any) http.HandlerFunc {
297 t.Helper()
298 return func(w http.ResponseWriter, _ *http.Request) {
299 w.WriteHeader(code)
300 // Some tests do not expect to return a JSON object, such as fetching a raw pull request diff,
301 // so allow strings to be returned directly.
302 s, ok := body.(string)
303 if ok {
304 _, _ = w.Write([]byte(s))
305 return
306 }
307
308 b, err := json.Marshal(body)
309 require.NoError(t, err)
310 _, _ = w.Write(b)
311 }
312}
313
314// createMCPRequest is a helper function to create a MCP request with the given arguments.
315func createMCPRequest(args any) mcp.CallToolRequest {

Calls 2

WriteHeaderMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected