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)
| 294 | // mockResponse is a helper function to create a mock HTTP response handler |
| 295 | // that returns a specified status code and marshaled body. |
| 296 | func 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. |
| 315 | func createMCPRequest(args any) mcp.CallToolRequest { |
no test coverage detected