TestValidationErrors 测试各种验证错误
(t *testing.T)
| 408 | |
| 409 | // TestValidationErrors 测试各种验证错误 |
| 410 | func 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 验证 |
| 458 | func TestContentTypeValidation(t *testing.T) { |
nothing calls this directly
no test coverage detected