MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / TestPostAcceptsJSONOnly

Function TestPostAcceptsJSONOnly

server/mcp/handler_test.go:242–270  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

240}
241
242func TestPostAcceptsJSONOnly(t *testing.T) {
243 gin.SetMode(gin.TestMode)
244 srv := newTestServer(nil)
245
246 r := gin.New()
247 r.POST("/mcp", func(c *gin.Context) {
248 common.GinAppendValues(c, conf.UserKey, &model.User{ID: 1, Role: model.ADMIN})
249 srv.handlePost(c)
250 })
251
252 req := httptest.NewRequest(http.MethodPost, "http://example.com/mcp", strings.NewReader(`{
253 "jsonrpc":"2.0",
254 "id":1,
255 "method":"initialize"
256 }`))
257 req.Header.Set("Accept", "application/json")
258 req.Header.Set("Origin", "http://example.com")
259
260 w := httptest.NewRecorder()
261 r.ServeHTTP(w, req)
262
263 if w.Code != http.StatusOK {
264 t.Fatalf("unexpected status: got %d want %d", w.Code, http.StatusOK)
265 }
266 resp := decodeResponse(t, w)
267 if resp.Error != nil {
268 t.Fatalf("unexpected error response: %+v", resp.Error)
269 }
270}
271
272func TestPostAcceptsWildcardAccept(t *testing.T) {
273 gin.SetMode(gin.TestMode)

Callers

nothing calls this directly

Calls 6

GinAppendValuesFunction · 0.92
newTestServerFunction · 0.85
decodeResponseFunction · 0.85
handlePostMethod · 0.80
ServeHTTPMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected