TestContentTypeValidation 测试 Content-Type 验证
(t *testing.T)
| 456 | |
| 457 | // TestContentTypeValidation 测试 Content-Type 验证 |
| 458 | func TestContentTypeValidation(t *testing.T) { |
| 459 | srv, cleanup := setupTestServer(t) |
| 460 | defer cleanup() |
| 461 | |
| 462 | t.Run("MissingContentType", func(t *testing.T) { |
| 463 | body := `{"template_id": "chat"}` |
| 464 | req := httptest.NewRequest(http.MethodPost, "/v1/agents", strings.NewReader(body)) |
| 465 | // 不设置 Content-Type |
| 466 | w := httptest.NewRecorder() |
| 467 | |
| 468 | srv.Router().ServeHTTP(w, req) |
| 469 | |
| 470 | // Gin 默认会尝试解析,但可能失败 |
| 471 | assert.NotEqual(t, http.StatusOK, w.Code) |
| 472 | }) |
| 473 | |
| 474 | t.Run("WrongContentType", func(t *testing.T) { |
| 475 | t.Skip("Content-Type validation varies by implementation") |
| 476 | }) |
| 477 | } |
| 478 | |
| 479 | // TestQueryParameters 测试查询参数 |
| 480 | func TestQueryParameters(t *testing.T) { |
nothing calls this directly
no test coverage detected