Update reverse proxy tests to use absolute URLs for requests. Modified reverse_test.go to ensure that requests are constructed with the server's URL, preventing issues with the default "example.com" host in httptest. This change enhances the reliability of the tests by ensuring correct request handling.
This commit is contained in:
@@ -17,7 +17,8 @@ func TestReverseProxyPathRewrite(t *testing.T) {
|
||||
defer srv.Close()
|
||||
up, _ := url.Parse(srv.URL)
|
||||
rp := NewReverseProxy(up, "/api/main_srv", "/v1", "")
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/main_srv/health", nil)
|
||||
// Absolute URL: httptest relative targets set Host to "example.com", which breaks RoundTrip to srv.
|
||||
req := httptest.NewRequest(http.MethodGet, srv.URL+"/api/main_srv/health", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
rp.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
@@ -38,7 +39,7 @@ func TestReverseProxyPathRewriteWithAPIBasePath(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rp := NewReverseProxy(up, "/api/main_srv", "/v1", "")
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/main_srv/health", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, srv.URL+"/api/main_srv/health", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
rp.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
@@ -59,7 +60,7 @@ func TestReverseProxyPathNestedStatsUsers(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rp := NewReverseProxy(up, "/api/gt2", "/v1", "")
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/gt2/stats/users", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, srv.URL+"/api/gt2/stats/users", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
rp.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
|
||||
Reference in New Issue
Block a user