@@ -89,13 +89,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
89
89
// Then, for each new group it performs just one request to the API server:
90
90
// GET https://host/apis/<group>/<version>
91
91
92
- httpClient , err := rest .HTTPClientFor (restCfg )
93
- g .Expect (err ).NotTo (gmg .HaveOccurred ())
94
-
95
- crt := newCountingRoundTripper (httpClient .Transport )
96
- httpClient .Transport = crt
92
+ var crt * countingRoundTripper
93
+ restCfg := rest .CopyConfig (restCfg )
94
+ restCfg .WrapTransport = func (rt http.RoundTripper ) http.RoundTripper {
95
+ crt = newCountingRoundTripper (rt )
96
+ return crt
97
+ }
97
98
98
- lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , httpClient , apiutil .WithExperimentalLazyMapper )
99
+ lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , apiutil .WithExperimentalLazyMapper )
99
100
g .Expect (err ).NotTo (gmg .HaveOccurred ())
100
101
101
102
// There are no requests before any call
@@ -138,13 +139,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
138
139
t .Run ("LazyRESTMapper should cache fetched data and doesn't perform any additional requests" , func (t * testing.T ) {
139
140
g := gmg .NewWithT (t )
140
141
141
- httpClient , err := rest .HTTPClientFor (restCfg )
142
- g .Expect (err ).NotTo (gmg .HaveOccurred ())
142
+ var crt * countingRoundTripper
143
+ restCfg := rest .CopyConfig (restCfg )
144
+ restCfg .WrapTransport = func (rt http.RoundTripper ) http.RoundTripper {
145
+ crt = newCountingRoundTripper (rt )
146
+ return crt
147
+ }
143
148
144
- crt := newCountingRoundTripper (httpClient .Transport )
145
- httpClient .Transport = crt
146
-
147
- lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , httpClient , apiutil .WithExperimentalLazyMapper )
149
+ lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , apiutil .WithExperimentalLazyMapper )
148
150
g .Expect (err ).NotTo (gmg .HaveOccurred ())
149
151
150
152
g .Expect (crt .GetRequestCount ()).To (gmg .Equal (0 ))
@@ -175,13 +177,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
175
177
t .Run ("LazyRESTMapper should work correctly with empty versions list" , func (t * testing.T ) {
176
178
g := gmg .NewWithT (t )
177
179
178
- httpClient , err := rest .HTTPClientFor (restCfg )
179
- g .Expect (err ).NotTo (gmg .HaveOccurred ())
180
-
181
- crt := newCountingRoundTripper (httpClient .Transport )
182
- httpClient .Transport = crt
180
+ var crt * countingRoundTripper
181
+ restCfg := rest .CopyConfig (restCfg )
182
+ restCfg .WrapTransport = func (rt http.RoundTripper ) http.RoundTripper {
183
+ crt = newCountingRoundTripper (rt )
184
+ return crt
185
+ }
183
186
184
- lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , httpClient , apiutil .WithExperimentalLazyMapper )
187
+ lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , apiutil .WithExperimentalLazyMapper )
185
188
g .Expect (err ).NotTo (gmg .HaveOccurred ())
186
189
187
190
g .Expect (crt .GetRequestCount ()).To (gmg .Equal (0 ))
@@ -211,13 +214,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
211
214
t .Run ("LazyRESTMapper should work correctly with multiple API group versions" , func (t * testing.T ) {
212
215
g := gmg .NewWithT (t )
213
216
214
- httpClient , err := rest .HTTPClientFor (restCfg )
215
- g .Expect (err ).NotTo (gmg .HaveOccurred ())
216
-
217
- crt := newCountingRoundTripper (httpClient .Transport )
218
- httpClient .Transport = crt
217
+ var crt * countingRoundTripper
218
+ restCfg := rest .CopyConfig (restCfg )
219
+ restCfg .WrapTransport = func (rt http.RoundTripper ) http.RoundTripper {
220
+ crt = newCountingRoundTripper (rt )
221
+ return crt
222
+ }
219
223
220
- lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , httpClient , apiutil .WithExperimentalLazyMapper )
224
+ lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , apiutil .WithExperimentalLazyMapper )
221
225
g .Expect (err ).NotTo (gmg .HaveOccurred ())
222
226
223
227
g .Expect (crt .GetRequestCount ()).To (gmg .Equal (0 ))
@@ -246,13 +250,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
246
250
t .Run ("LazyRESTMapper should work correctly with different API group versions" , func (t * testing.T ) {
247
251
g := gmg .NewWithT (t )
248
252
249
- httpClient , err := rest .HTTPClientFor (restCfg )
250
- g .Expect (err ).NotTo (gmg .HaveOccurred ())
251
-
252
- crt := newCountingRoundTripper (httpClient .Transport )
253
- httpClient .Transport = crt
253
+ var crt * countingRoundTripper
254
+ restCfg := rest .CopyConfig (restCfg )
255
+ restCfg .WrapTransport = func (rt http.RoundTripper ) http.RoundTripper {
256
+ crt = newCountingRoundTripper (rt )
257
+ return crt
258
+ }
254
259
255
- lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , httpClient , apiutil .WithExperimentalLazyMapper )
260
+ lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , apiutil .WithExperimentalLazyMapper )
256
261
g .Expect (err ).NotTo (gmg .HaveOccurred ())
257
262
258
263
g .Expect (crt .GetRequestCount ()).To (gmg .Equal (0 ))
@@ -290,13 +295,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
290
295
291
296
// After initialization for each invalid group the mapper performs just 1 request to the API server.
292
297
293
- httpClient , err := rest .HTTPClientFor (restCfg )
294
- g .Expect (err ).NotTo (gmg .HaveOccurred ())
295
-
296
- crt := newCountingRoundTripper (httpClient .Transport )
297
- httpClient .Transport = crt
298
+ var crt * countingRoundTripper
299
+ restCfg := rest .CopyConfig (restCfg )
300
+ restCfg .WrapTransport = func (rt http.RoundTripper ) http.RoundTripper {
301
+ crt = newCountingRoundTripper (rt )
302
+ return crt
303
+ }
298
304
299
- lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , httpClient , apiutil .WithExperimentalLazyMapper )
305
+ lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , apiutil .WithExperimentalLazyMapper )
300
306
g .Expect (err ).NotTo (gmg .HaveOccurred ())
301
307
302
308
_ , err = lazyRestMapper .RESTMapping (schema.GroupKind {Group : "INVALID1" }, "v1" )
@@ -328,14 +334,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
328
334
g := gmg .NewWithT (t )
329
335
330
336
// After initialization for each invalid resource the mapper performs just 1 request to the API server.
337
+ var crt * countingRoundTripper
338
+ restCfg := rest .CopyConfig (restCfg )
339
+ restCfg .WrapTransport = func (rt http.RoundTripper ) http.RoundTripper {
340
+ crt = newCountingRoundTripper (rt )
341
+ return crt
342
+ }
331
343
332
- httpClient , err := rest .HTTPClientFor (restCfg )
333
- g .Expect (err ).NotTo (gmg .HaveOccurred ())
334
-
335
- crt := newCountingRoundTripper (httpClient .Transport )
336
- httpClient .Transport = crt
337
-
338
- lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , httpClient , apiutil .WithExperimentalLazyMapper )
344
+ lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , apiutil .WithExperimentalLazyMapper )
339
345
g .Expect (err ).NotTo (gmg .HaveOccurred ())
340
346
341
347
_ , err = lazyRestMapper .RESTMapping (schema.GroupKind {Group : "apps" , Kind : "INVALID" })
@@ -367,14 +373,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
367
373
g := gmg .NewWithT (t )
368
374
369
375
// After initialization, for each invalid resource mapper performs 1 requests to the API server.
370
-
371
- httpClient , err := rest .HTTPClientFor (restCfg )
372
- g . Expect ( err ). NotTo ( gmg . HaveOccurred ())
373
-
374
- crt := newCountingRoundTripper ( httpClient . Transport )
375
- httpClient . Transport = crt
376
-
377
- lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , httpClient , apiutil .WithExperimentalLazyMapper )
376
+ var crt * countingRoundTripper
377
+ restCfg := rest .CopyConfig (restCfg )
378
+ restCfg . WrapTransport = func ( rt http. RoundTripper ) http. RoundTripper {
379
+ crt = newCountingRoundTripper ( rt )
380
+ return crt
381
+ }
382
+
383
+ lazyRestMapper , err := apiutil .NewDynamicRESTMapper (restCfg , apiutil .WithExperimentalLazyMapper )
378
384
g .Expect (err ).NotTo (gmg .HaveOccurred ())
379
385
380
386
_ , err = lazyRestMapper .RESTMapping (schema.GroupKind {Group : "apps" , Kind : "deployment" }, "INVALID" )
0 commit comments