@@ -42,6 +42,7 @@ func TestCallWithRecorder(t *testing.T) {
42
42
clientSetup func (* UnstructuredClient )
43
43
expected interface {}
44
44
expectedError string
45
+ expectedURL string
45
46
}{
46
47
{
47
48
name : "path with slash in path parameter" ,
@@ -179,6 +180,26 @@ func TestCallWithRecorder(t *testing.T) {
179
180
},
180
181
expectedError : "unexpected status: 401: invalid status code: 401" ,
181
182
},
183
+ {
184
+ name : "server override in operation" ,
185
+ handler : func (w http.ResponseWriter , r * http.Request ) {
186
+ // Verify that the request is using the override server URL
187
+ // The mock transport doesn't actually change the host, but we can verify
188
+ // the path and that the request was made
189
+ assert .Equal (t , "GET" , r .Method )
190
+ assert .Equal (t , "/api/override" , r .URL .Path )
191
+
192
+ w .Header ().Set ("Content-Type" , "application/json" )
193
+ w .WriteHeader (http .StatusOK )
194
+ json .NewEncoder (w ).Encode (map [string ]interface {}{"message" : "override success" })
195
+ },
196
+ path : "/api/override" ,
197
+ opts : & RequestConfiguration {
198
+ Method : "GET" ,
199
+ },
200
+ expected : map [string ]interface {}{"message" : "override success" },
201
+ expectedURL : "http://override.example.com/api/override" ,
202
+ },
182
203
}
183
204
184
205
for _ , tt := range tests {
@@ -188,6 +209,11 @@ func TestCallWithRecorder(t *testing.T) {
188
209
handler : tt .handler ,
189
210
}
190
211
212
+ // If we need to verify the URL (we set the field in the test case), capture it
213
+ if tt .expectedURL != "" {
214
+ mockTransport .capturedURL = ""
215
+ }
216
+
191
217
// Create test client
192
218
client := createTestClient (t )
193
219
if tt .clientSetup != nil {
@@ -200,6 +226,11 @@ func TestCallWithRecorder(t *testing.T) {
200
226
// Call the method under test
201
227
result , err := client .Call (context .Background (), testClient , tt .path , tt .opts )
202
228
229
+ // Verify the URL if expected, if we set the field in the test case
230
+ if tt .expectedURL != "" {
231
+ assert .Equal (t , tt .expectedURL , mockTransport .capturedURL )
232
+ }
233
+
203
234
if tt .expectedError != "" {
204
235
require .Error (t , err )
205
236
assert .Contains (t , err .Error (), tt .expectedError )
@@ -227,10 +258,16 @@ func TestCallWithRecorder(t *testing.T) {
227
258
228
259
// mockTransport implements http.RoundTripper using a ResponseRecorder
229
260
type mockTransport struct {
230
- handler http.HandlerFunc
261
+ handler http.HandlerFunc
262
+ capturedURL string
231
263
}
232
264
233
265
func (m * mockTransport ) RoundTrip (req * http.Request ) (* http.Response , error ) {
266
+ // Capture the full URL for verification
267
+ if m .capturedURL == "" {
268
+ m .capturedURL = req .URL .String ()
269
+ }
270
+
234
271
// Create a ResponseRecorder
235
272
rr := httptest .NewRecorder ()
236
273
0 commit comments