Skip to content

Commit c31cb14

Browse files
committed
Update tests for 0.14
1 parent f4d10a3 commit c31cb14

File tree

1 file changed

+57
-51
lines changed

1 file changed

+57
-51
lines changed

pkg/client/apiutil/lazyrestmapper_test.go

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
8989
// Then, for each new group it performs just one request to the API server:
9090
// GET https://host/apis/<group>/<version>
9191

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+
}
9798

98-
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, httpClient, apiutil.WithExperimentalLazyMapper)
99+
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, apiutil.WithExperimentalLazyMapper)
99100
g.Expect(err).NotTo(gmg.HaveOccurred())
100101

101102
// There are no requests before any call
@@ -138,13 +139,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
138139
t.Run("LazyRESTMapper should cache fetched data and doesn't perform any additional requests", func(t *testing.T) {
139140
g := gmg.NewWithT(t)
140141

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+
}
143148

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)
148150
g.Expect(err).NotTo(gmg.HaveOccurred())
149151

150152
g.Expect(crt.GetRequestCount()).To(gmg.Equal(0))
@@ -175,13 +177,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
175177
t.Run("LazyRESTMapper should work correctly with empty versions list", func(t *testing.T) {
176178
g := gmg.NewWithT(t)
177179

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+
}
183186

184-
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, httpClient, apiutil.WithExperimentalLazyMapper)
187+
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, apiutil.WithExperimentalLazyMapper)
185188
g.Expect(err).NotTo(gmg.HaveOccurred())
186189

187190
g.Expect(crt.GetRequestCount()).To(gmg.Equal(0))
@@ -211,13 +214,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
211214
t.Run("LazyRESTMapper should work correctly with multiple API group versions", func(t *testing.T) {
212215
g := gmg.NewWithT(t)
213216

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+
}
219223

220-
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, httpClient, apiutil.WithExperimentalLazyMapper)
224+
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, apiutil.WithExperimentalLazyMapper)
221225
g.Expect(err).NotTo(gmg.HaveOccurred())
222226

223227
g.Expect(crt.GetRequestCount()).To(gmg.Equal(0))
@@ -246,13 +250,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
246250
t.Run("LazyRESTMapper should work correctly with different API group versions", func(t *testing.T) {
247251
g := gmg.NewWithT(t)
248252

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+
}
254259

255-
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, httpClient, apiutil.WithExperimentalLazyMapper)
260+
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, apiutil.WithExperimentalLazyMapper)
256261
g.Expect(err).NotTo(gmg.HaveOccurred())
257262

258263
g.Expect(crt.GetRequestCount()).To(gmg.Equal(0))
@@ -290,13 +295,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
290295

291296
// After initialization for each invalid group the mapper performs just 1 request to the API server.
292297

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+
}
298304

299-
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, httpClient, apiutil.WithExperimentalLazyMapper)
305+
lazyRestMapper, err := apiutil.NewDynamicRESTMapper(restCfg, apiutil.WithExperimentalLazyMapper)
300306
g.Expect(err).NotTo(gmg.HaveOccurred())
301307

302308
_, err = lazyRestMapper.RESTMapping(schema.GroupKind{Group: "INVALID1"}, "v1")
@@ -328,14 +334,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
328334
g := gmg.NewWithT(t)
329335

330336
// 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+
}
331343

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)
339345
g.Expect(err).NotTo(gmg.HaveOccurred())
340346

341347
_, err = lazyRestMapper.RESTMapping(schema.GroupKind{Group: "apps", Kind: "INVALID"})
@@ -367,14 +373,14 @@ func TestLazyRestMapperProvider(t *testing.T) {
367373
g := gmg.NewWithT(t)
368374

369375
// 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)
378384
g.Expect(err).NotTo(gmg.HaveOccurred())
379385

380386
_, err = lazyRestMapper.RESTMapping(schema.GroupKind{Group: "apps", Kind: "deployment"}, "INVALID")

0 commit comments

Comments
 (0)