TestNewDockerHandlerWithMockDocker mocks the Docker API to test the actual HTTP handler behavior This is a more comprehensive test that verifies the full request/response chain
(t *testing.T)
| 397 | // TestNewDockerHandlerWithMockDocker mocks the Docker API to test the actual HTTP handler behavior |
| 398 | // This is a more comprehensive test that verifies the full request/response chain |
| 399 | func TestNewDockerHandlerWithMockDocker(t *testing.T) { |
| 400 | // Set up environment |
| 401 | DockerContainers = true |
| 402 | DockerPost = true |
| 403 | |
| 404 | // Create the handler |
| 405 | handler := NewHandler() |
| 406 | |
| 407 | // Test a valid request |
| 408 | req, _ := http.NewRequest(http.MethodGet, "/containers", nil) |
| 409 | recorder := httptest.NewRecorder() |
| 410 | handler.ServeHTTP(recorder, req) |
| 411 | |
| 412 | if recorder.Code != http.StatusOK { |
| 413 | t.Errorf("Expected status OK for /containers, got %d", recorder.Code) |
| 414 | } |
| 415 | |
| 416 | // Test a disallowed path |
| 417 | DockerContainers = false |
| 418 | handler = NewHandler() // recreate with new env |
| 419 | |
| 420 | req, _ = http.NewRequest(http.MethodGet, "/containers", nil) |
| 421 | recorder = httptest.NewRecorder() |
| 422 | handler.ServeHTTP(recorder, req) |
| 423 | |
| 424 | if recorder.Code != http.StatusForbidden { |
| 425 | t.Errorf("Expected status Forbidden for /containers when disabled, got %d", recorder.Code) |
| 426 | } |
| 427 | } |
nothing calls this directly
no test coverage detected