MCPcopy Create free account
hub / github.com/appleboy/loadbalancer-algorithms / TestProxy_ServeHTTP

Function TestProxy_ServeHTTP

proxy/proxy_test.go:10–34  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestProxy_ServeHTTP(t *testing.T) {
11 // Create a test server
12 ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13 w.WriteHeader(http.StatusOK)
14 }))
15 defer ts.Close()
16
17 // Create a new proxy with the test server's URL
18 proxyURL, _ := url.Parse(ts.URL)
19 proxy := NewProxy("foobar", proxyURL)
20
21 // Create a mock request
22 req, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
23
24 // Create a mock response recorder
25 rr := httptest.NewRecorder()
26
27 // Call the ServeHTTP method
28 proxy.ServeHTTP(rr, req)
29
30 // Check the response status code
31 if rr.Code != http.StatusOK {
32 t.Errorf("expected status code %d, got %d", http.StatusOK, rr.Code)
33 }
34}

Callers

nothing calls this directly

Calls 2

ServeHTTPMethod · 0.95
NewProxyFunction · 0.85

Tested by

no test coverage detected