MCPcopy Create free account
hub / github.com/astercloud/aster / TestValidationErrors

Function TestValidationErrors

server/handlers_test.go:410–455  ·  view source on GitHub ↗

TestValidationErrors 测试各种验证错误

(t *testing.T)

Source from the content-addressed store, hash-verified

408
409// TestValidationErrors 测试各种验证错误
410func TestValidationErrors(t *testing.T) {
411 srv, cleanup := setupTestServer(t)
412 defer cleanup()
413
414 tests := []struct {
415 name string
416 method string
417 path string
418 body string
419 expectedStatus int
420 }{
421 {
422 name: "EmptyAgentName",
423 method: http.MethodPost,
424 path: "/v1/agents",
425 body: `{"template_id": ""}`,
426 expectedStatus: http.StatusBadRequest,
427 },
428 {
429 name: "InvalidToolSchema",
430 method: http.MethodPost,
431 path: "/v1/tools",
432 body: `{"name": "test", "schema": "invalid"}`,
433 expectedStatus: http.StatusBadRequest,
434 },
435 {
436 name: "InvalidRoomName",
437 method: http.MethodPost,
438 path: "/v1/rooms",
439 body: `{"name": ""}`,
440 expectedStatus: http.StatusBadRequest,
441 },
442 }
443
444 for _, tt := range tests {
445 t.Run(tt.name, func(t *testing.T) {
446 req := httptest.NewRequest(tt.method, tt.path, strings.NewReader(tt.body))
447 req.Header.Set("Content-Type", "application/json")
448 w := httptest.NewRecorder()
449
450 srv.Router().ServeHTTP(w, req)
451
452 assert.Equal(t, tt.expectedStatus, w.Code)
453 })
454 }
455}
456
457// TestContentTypeValidation 测试 Content-Type 验证
458func TestContentTypeValidation(t *testing.T) {

Callers

nothing calls this directly

Calls 5

setupTestServerFunction · 0.85
SetMethod · 0.65
RunMethod · 0.45
ServeHTTPMethod · 0.45
RouterMethod · 0.45

Tested by

no test coverage detected