MCPcopy Index your code
hub / github.com/yusing/godoxy / TestNewDockerHandlerWithMockDocker

Function TestNewDockerHandlerWithMockDocker

socket-proxy/pkg/handler_test.go:399–427  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
399func 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}

Callers

nothing calls this directly

Calls 2

ServeHTTPMethod · 0.95
NewHandlerFunction · 0.70

Tested by

no test coverage detected