TestTelemetryHandlers 测试 Telemetry 相关的处理器
(t *testing.T)
| 174 | |
| 175 | // TestTelemetryHandlers 测试 Telemetry 相关的处理器 |
| 176 | func TestTelemetryHandlers(t *testing.T) { |
| 177 | srv, cleanup := setupTestServer(t) |
| 178 | defer cleanup() |
| 179 | |
| 180 | t.Run("RecordMetric", func(t *testing.T) { |
| 181 | body := `{ |
| 182 | "name": "test_metric", |
| 183 | "type": "counter", |
| 184 | "value": 42.0, |
| 185 | "tags": { |
| 186 | "env": "test" |
| 187 | } |
| 188 | }` |
| 189 | |
| 190 | req := httptest.NewRequest(http.MethodPost, "/v1/telemetry/metrics", strings.NewReader(body)) |
| 191 | req.Header.Set("Content-Type", "application/json") |
| 192 | w := httptest.NewRecorder() |
| 193 | |
| 194 | srv.Router().ServeHTTP(w, req) |
| 195 | |
| 196 | assert.Equal(t, http.StatusCreated, w.Code) |
| 197 | }) |
| 198 | |
| 199 | t.Run("ListMetrics", func(t *testing.T) { |
| 200 | req := httptest.NewRequest(http.MethodGet, "/v1/telemetry/metrics", nil) |
| 201 | w := httptest.NewRecorder() |
| 202 | |
| 203 | srv.Router().ServeHTTP(w, req) |
| 204 | |
| 205 | assert.Equal(t, http.StatusOK, w.Code) |
| 206 | }) |
| 207 | |
| 208 | t.Run("RecordTrace", func(t *testing.T) { |
| 209 | t.Skip("Trace recording needs proper implementation") |
| 210 | }) |
| 211 | |
| 212 | t.Run("RecordLog", func(t *testing.T) { |
| 213 | body := `{ |
| 214 | "level": "info", |
| 215 | "message": "Test log message", |
| 216 | "timestamp": "2024-01-01T00:00:00Z" |
| 217 | }` |
| 218 | |
| 219 | req := httptest.NewRequest(http.MethodPost, "/v1/telemetry/logs", strings.NewReader(body)) |
| 220 | req.Header.Set("Content-Type", "application/json") |
| 221 | w := httptest.NewRecorder() |
| 222 | |
| 223 | srv.Router().ServeHTTP(w, req) |
| 224 | |
| 225 | assert.Equal(t, http.StatusCreated, w.Code) |
| 226 | }) |
| 227 | } |
| 228 | |
| 229 | // TestSystemHandlers 测试 System 相关的处理器 |
| 230 | func TestSystemHandlers(t *testing.T) { |
nothing calls this directly
no test coverage detected