(t *testing.T)
| 327 | } |
| 328 | |
| 329 | func TestAdminHandlerBuiltinRouteErrors(t *testing.T) { |
| 330 | initAdminMetrics() |
| 331 | |
| 332 | cfg := &Config{ |
| 333 | Admin: &AdminConfig{ |
| 334 | Listen: "localhost:2019", |
| 335 | }, |
| 336 | } |
| 337 | |
| 338 | // Build the admin handler directly (no listener active) |
| 339 | addr, err := ParseNetworkAddress("localhost:2019") |
| 340 | if err != nil { |
| 341 | t.Fatalf("Failed to parse address: %v", err) |
| 342 | } |
| 343 | handler, err := cfg.Admin.newAdminHandler(addr, false, Context{}) |
| 344 | if err != nil { |
| 345 | t.Fatalf("Failed to create admin handler: %v", err) |
| 346 | } |
| 347 | |
| 348 | tests := []struct { |
| 349 | name string |
| 350 | path string |
| 351 | method string |
| 352 | expectedStatus int |
| 353 | }{ |
| 354 | { |
| 355 | name: "stop endpoint wrong method", |
| 356 | path: "/stop", |
| 357 | method: http.MethodGet, |
| 358 | expectedStatus: http.StatusMethodNotAllowed, |
| 359 | }, |
| 360 | { |
| 361 | name: "config endpoint wrong content-type", |
| 362 | path: "/config/", |
| 363 | method: http.MethodPost, |
| 364 | expectedStatus: http.StatusBadRequest, |
| 365 | }, |
| 366 | { |
| 367 | name: "config ID missing ID", |
| 368 | path: "/id/", |
| 369 | method: http.MethodGet, |
| 370 | expectedStatus: http.StatusBadRequest, |
| 371 | }, |
| 372 | } |
| 373 | |
| 374 | for _, test := range tests { |
| 375 | t.Run(test.name, func(t *testing.T) { |
| 376 | req := httptest.NewRequest(test.method, fmt.Sprintf("http://localhost:2019%s", test.path), nil) |
| 377 | rr := httptest.NewRecorder() |
| 378 | |
| 379 | handler.ServeHTTP(rr, req) |
| 380 | |
| 381 | if rr.Code != test.expectedStatus { |
| 382 | t.Errorf("expected status %d but got %d", test.expectedStatus, rr.Code) |
| 383 | } |
| 384 | |
| 385 | metricValue := testGetMetricValue(map[string]string{ |
| 386 | "path": test.path, |
nothing calls this directly
no test coverage detected