| 8 | ) |
| 9 | |
| 10 | func 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 | } |