1
- package fake
1
+ package interceptor
2
2
3
3
import (
4
4
"context"
5
+ "sigs.k8s.io/controller-runtime/pkg/client/fake"
5
6
6
7
. "github.com/onsi/ginkgo/v2"
7
8
. "github.com/onsi/gomega"
@@ -10,12 +11,12 @@ import (
10
11
"sigs.k8s.io/controller-runtime/pkg/client"
11
12
)
12
13
13
- var _ = Describe ("Interceptor " , func () {
14
- wrappedClient := NewClientBuilder ().Build ()
14
+ var _ = Describe ("NewClient " , func () {
15
+ wrappedClient := fake . NewClientBuilder ().Build ()
15
16
ctx := context .Background ()
16
17
It ("should call the provided Get function" , func () {
17
18
var called bool
18
- client := Interceptor (wrappedClient , InterceptorFns {
19
+ client := NewClient (wrappedClient , Fns {
19
20
Get : func (ctx context.Context , client client.WithWatch , key client.ObjectKey , obj client.Object , opts ... client.GetOption ) error {
20
21
called = true
21
22
return nil
@@ -26,19 +27,19 @@ var _ = Describe("Interceptor", func() {
26
27
})
27
28
It ("should call the underlying client if the provided Get function is nil" , func () {
28
29
var called bool
29
- client1 := Interceptor (wrappedClient , InterceptorFns {
30
+ client1 := NewClient (wrappedClient , Fns {
30
31
Get : func (ctx context.Context , client client.WithWatch , key client.ObjectKey , obj client.Object , opts ... client.GetOption ) error {
31
32
called = true
32
33
return nil
33
34
},
34
35
})
35
- client2 := Interceptor (client1 , InterceptorFns {})
36
+ client2 := NewClient (client1 , Fns {})
36
37
_ = client2 .Get (ctx , types.NamespacedName {}, nil )
37
38
Expect (called ).To (BeTrue ())
38
39
})
39
40
It ("should call the provided List function" , func () {
40
41
var called bool
41
- client := Interceptor (wrappedClient , InterceptorFns {
42
+ client := NewClient (wrappedClient , Fns {
42
43
List : func (ctx context.Context , client client.WithWatch , list client.ObjectList , opts ... client.ListOption ) error {
43
44
called = true
44
45
return nil
@@ -49,19 +50,19 @@ var _ = Describe("Interceptor", func() {
49
50
})
50
51
It ("should call the underlying client if the provided List function is nil" , func () {
51
52
var called bool
52
- client1 := Interceptor (wrappedClient , InterceptorFns {
53
+ client1 := NewClient (wrappedClient , Fns {
53
54
List : func (ctx context.Context , client client.WithWatch , list client.ObjectList , opts ... client.ListOption ) error {
54
55
called = true
55
56
return nil
56
57
},
57
58
})
58
- client2 := Interceptor (client1 , InterceptorFns {})
59
+ client2 := NewClient (client1 , Fns {})
59
60
_ = client2 .List (ctx , nil )
60
61
Expect (called ).To (BeTrue ())
61
62
})
62
63
It ("should call the provided Create function" , func () {
63
64
var called bool
64
- client := Interceptor (wrappedClient , InterceptorFns {
65
+ client := NewClient (wrappedClient , Fns {
65
66
Create : func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.CreateOption ) error {
66
67
called = true
67
68
return nil
@@ -72,19 +73,19 @@ var _ = Describe("Interceptor", func() {
72
73
})
73
74
It ("should call the underlying client if the provided Create function is nil" , func () {
74
75
var called bool
75
- client1 := Interceptor (wrappedClient , InterceptorFns {
76
+ client1 := NewClient (wrappedClient , Fns {
76
77
Create : func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.CreateOption ) error {
77
78
called = true
78
79
return nil
79
80
},
80
81
})
81
- client2 := Interceptor (client1 , InterceptorFns {})
82
+ client2 := NewClient (client1 , Fns {})
82
83
_ = client2 .Create (ctx , nil )
83
84
Expect (called ).To (BeTrue ())
84
85
})
85
86
It ("should call the provided Delete function" , func () {
86
87
var called bool
87
- client := Interceptor (wrappedClient , InterceptorFns {
88
+ client := NewClient (wrappedClient , Fns {
88
89
Delete : func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.DeleteOption ) error {
89
90
called = true
90
91
return nil
@@ -95,19 +96,19 @@ var _ = Describe("Interceptor", func() {
95
96
})
96
97
It ("should call the underlying client if the provided Delete function is nil" , func () {
97
98
var called bool
98
- client1 := Interceptor (wrappedClient , InterceptorFns {
99
+ client1 := NewClient (wrappedClient , Fns {
99
100
Delete : func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.DeleteOption ) error {
100
101
called = true
101
102
return nil
102
103
},
103
104
})
104
- client2 := Interceptor (client1 , InterceptorFns {})
105
+ client2 := NewClient (client1 , Fns {})
105
106
_ = client2 .Delete (ctx , nil )
106
107
Expect (called ).To (BeTrue ())
107
108
})
108
109
It ("should call the provided DeleteAllOf function" , func () {
109
110
var called bool
110
- client := Interceptor (wrappedClient , InterceptorFns {
111
+ client := NewClient (wrappedClient , Fns {
111
112
DeleteAllOf : func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.DeleteAllOfOption ) error {
112
113
called = true
113
114
return nil
@@ -118,19 +119,19 @@ var _ = Describe("Interceptor", func() {
118
119
})
119
120
It ("should call the underlying client if the provided DeleteAllOf function is nil" , func () {
120
121
var called bool
121
- client1 := Interceptor (wrappedClient , InterceptorFns {
122
+ client1 := NewClient (wrappedClient , Fns {
122
123
DeleteAllOf : func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.DeleteAllOfOption ) error {
123
124
called = true
124
125
return nil
125
126
},
126
127
})
127
- client2 := Interceptor (client1 , InterceptorFns {})
128
+ client2 := NewClient (client1 , Fns {})
128
129
_ = client2 .DeleteAllOf (ctx , nil )
129
130
Expect (called ).To (BeTrue ())
130
131
})
131
132
It ("should call the provided Update function" , func () {
132
133
var called bool
133
- client := Interceptor (wrappedClient , InterceptorFns {
134
+ client := NewClient (wrappedClient , Fns {
134
135
Update : func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.UpdateOption ) error {
135
136
called = true
136
137
return nil
@@ -141,19 +142,19 @@ var _ = Describe("Interceptor", func() {
141
142
})
142
143
It ("should call the underlying client if the provided Update function is nil" , func () {
143
144
var called bool
144
- client1 := Interceptor (wrappedClient , InterceptorFns {
145
+ client1 := NewClient (wrappedClient , Fns {
145
146
Update : func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.UpdateOption ) error {
146
147
called = true
147
148
return nil
148
149
},
149
150
})
150
- client2 := Interceptor (client1 , InterceptorFns {})
151
+ client2 := NewClient (client1 , Fns {})
151
152
_ = client2 .Update (ctx , nil )
152
153
Expect (called ).To (BeTrue ())
153
154
})
154
155
It ("should call the provided Patch function" , func () {
155
156
var called bool
156
- client := Interceptor (wrappedClient , InterceptorFns {
157
+ client := NewClient (wrappedClient , Fns {
157
158
Patch : func (ctx context.Context , client client.WithWatch , obj client.Object , patch client.Patch , opts ... client.PatchOption ) error {
158
159
called = true
159
160
return nil
@@ -164,19 +165,19 @@ var _ = Describe("Interceptor", func() {
164
165
})
165
166
It ("should call the underlying client if the provided Patch function is nil" , func () {
166
167
var called bool
167
- client1 := Interceptor (wrappedClient , InterceptorFns {
168
+ client1 := NewClient (wrappedClient , Fns {
168
169
Patch : func (ctx context.Context , client client.WithWatch , obj client.Object , patch client.Patch , opts ... client.PatchOption ) error {
169
170
called = true
170
171
return nil
171
172
},
172
173
})
173
- client2 := Interceptor (client1 , InterceptorFns {})
174
+ client2 := NewClient (client1 , Fns {})
174
175
_ = client2 .Patch (ctx , nil , nil )
175
176
Expect (called ).To (BeTrue ())
176
177
})
177
178
It ("should call the provided Watch function" , func () {
178
179
var called bool
179
- client := Interceptor (wrappedClient , InterceptorFns {
180
+ client := NewClient (wrappedClient , Fns {
180
181
Watch : func (ctx context.Context , client client.WithWatch , obj client.ObjectList , opts ... client.ListOption ) (watch.Interface , error ) {
181
182
called = true
182
183
return nil , nil
@@ -187,19 +188,19 @@ var _ = Describe("Interceptor", func() {
187
188
})
188
189
It ("should call the underlying client if the provided Watch function is nil" , func () {
189
190
var called bool
190
- client1 := Interceptor (wrappedClient , InterceptorFns {
191
+ client1 := NewClient (wrappedClient , Fns {
191
192
Watch : func (ctx context.Context , client client.WithWatch , obj client.ObjectList , opts ... client.ListOption ) (watch.Interface , error ) {
192
193
called = true
193
194
return nil , nil
194
195
},
195
196
})
196
- client2 := Interceptor (client1 , InterceptorFns {})
197
+ client2 := NewClient (client1 , Fns {})
197
198
_ , _ = client2 .Watch (ctx , nil )
198
199
Expect (called ).To (BeTrue ())
199
200
})
200
201
It ("should call the provided SubResource function" , func () {
201
202
var called bool
202
- client := Interceptor (wrappedClient , InterceptorFns {
203
+ client := NewClient (wrappedClient , Fns {
203
204
SubResource : func (client client.WithWatch , subResource string ) client.SubResourceClient {
204
205
called = true
205
206
return nil
@@ -210,19 +211,19 @@ var _ = Describe("Interceptor", func() {
210
211
})
211
212
It ("should call the underlying client if the provided SubResource function is nil" , func () {
212
213
var called bool
213
- client1 := Interceptor (wrappedClient , InterceptorFns {
214
+ client1 := NewClient (wrappedClient , Fns {
214
215
SubResource : func (client client.WithWatch , subResource string ) client.SubResourceClient {
215
216
called = true
216
217
return nil
217
218
},
218
219
})
219
- client2 := Interceptor (client1 , InterceptorFns {})
220
+ client2 := NewClient (client1 , Fns {})
220
221
_ = client2 .SubResource ("" )
221
222
Expect (called ).To (BeTrue ())
222
223
})
223
224
It ("should call the provided SubResource function with 'status' when calling Status()" , func () {
224
225
var called bool
225
- client := Interceptor (wrappedClient , InterceptorFns {
226
+ client := NewClient (wrappedClient , Fns {
226
227
SubResource : func (client client.WithWatch , subResource string ) client.SubResourceClient {
227
228
if subResource == "status" {
228
229
called = true
@@ -235,27 +236,27 @@ var _ = Describe("Interceptor", func() {
235
236
})
236
237
It ("should call the underlying client if the provided SubResource function is nil when calling Status" , func () {
237
238
var called bool
238
- client1 := Interceptor (wrappedClient , InterceptorFns {
239
+ client1 := NewClient (wrappedClient , Fns {
239
240
SubResource : func (client client.WithWatch , subResource string ) client.SubResourceClient {
240
241
if subResource == "status" {
241
242
called = true
242
243
}
243
244
return nil
244
245
},
245
246
})
246
- client2 := Interceptor (client1 , InterceptorFns {})
247
+ client2 := NewClient (client1 , Fns {})
247
248
_ = client2 .Status ()
248
249
Expect (called ).To (BeTrue ())
249
250
})
250
251
})
251
252
252
- var _ = Describe ("SubResourceInterceptor " , func () {
253
- wrappedClient := NewClientBuilder ().Build ()
253
+ var _ = Describe ("NewSubResourceClient " , func () {
254
+ wrappedClient := fake . NewClientBuilder ().Build ()
254
255
srClient := wrappedClient .SubResource ("test" )
255
256
ctx := context .Background ()
256
257
It ("should call the provided Get function" , func () {
257
258
var called bool
258
- client := SubResourceInterceptor (srClient , SubResourceInterceptorFns {
259
+ client := NewSubResourceClient (srClient , SubResourceInterceptorFns {
259
260
Get : func (ctx context.Context , client client.SubResourceClient , obj client.Object , subResource client.Object , opts ... client.SubResourceGetOption ) error {
260
261
called = true
261
262
return nil
@@ -266,19 +267,19 @@ var _ = Describe("SubResourceInterceptor", func() {
266
267
})
267
268
It ("should call the underlying client if the provided Get function is nil" , func () {
268
269
var called bool
269
- client1 := SubResourceInterceptor (srClient , SubResourceInterceptorFns {
270
+ client1 := NewSubResourceClient (srClient , SubResourceInterceptorFns {
270
271
Get : func (ctx context.Context , client client.SubResourceClient , obj client.Object , subResource client.Object , opts ... client.SubResourceGetOption ) error {
271
272
called = true
272
273
return nil
273
274
},
274
275
})
275
- client2 := SubResourceInterceptor (client1 , SubResourceInterceptorFns {})
276
+ client2 := NewSubResourceClient (client1 , SubResourceInterceptorFns {})
276
277
_ = client2 .Get (ctx , nil , nil )
277
278
Expect (called ).To (BeTrue ())
278
279
})
279
280
It ("should call the provided Update function" , func () {
280
281
var called bool
281
- client := SubResourceInterceptor (srClient , SubResourceInterceptorFns {
282
+ client := NewSubResourceClient (srClient , SubResourceInterceptorFns {
282
283
Update : func (ctx context.Context , client client.SubResourceClient , obj client.Object , opts ... client.SubResourceUpdateOption ) error {
283
284
called = true
284
285
return nil
@@ -289,19 +290,19 @@ var _ = Describe("SubResourceInterceptor", func() {
289
290
})
290
291
It ("should call the underlying client if the provided Update function is nil" , func () {
291
292
var called bool
292
- client1 := SubResourceInterceptor (srClient , SubResourceInterceptorFns {
293
+ client1 := NewSubResourceClient (srClient , SubResourceInterceptorFns {
293
294
Update : func (ctx context.Context , client client.SubResourceClient , obj client.Object , opts ... client.SubResourceUpdateOption ) error {
294
295
called = true
295
296
return nil
296
297
},
297
298
})
298
- client2 := SubResourceInterceptor (client1 , SubResourceInterceptorFns {})
299
+ client2 := NewSubResourceClient (client1 , SubResourceInterceptorFns {})
299
300
_ = client2 .Update (ctx , nil , nil )
300
301
Expect (called ).To (BeTrue ())
301
302
})
302
303
It ("should call the provided Patch function" , func () {
303
304
var called bool
304
- client := SubResourceInterceptor (srClient , SubResourceInterceptorFns {
305
+ client := NewSubResourceClient (srClient , SubResourceInterceptorFns {
305
306
Patch : func (ctx context.Context , client client.SubResourceClient , obj client.Object , patch client.Patch , opts ... client.SubResourcePatchOption ) error {
306
307
called = true
307
308
return nil
@@ -312,19 +313,19 @@ var _ = Describe("SubResourceInterceptor", func() {
312
313
})
313
314
It ("should call the underlying client if the provided Patch function is nil" , func () {
314
315
var called bool
315
- client1 := SubResourceInterceptor (srClient , SubResourceInterceptorFns {
316
+ client1 := NewSubResourceClient (srClient , SubResourceInterceptorFns {
316
317
Patch : func (ctx context.Context , client client.SubResourceClient , obj client.Object , patch client.Patch , opts ... client.SubResourcePatchOption ) error {
317
318
called = true
318
319
return nil
319
320
},
320
321
})
321
- client2 := SubResourceInterceptor (client1 , SubResourceInterceptorFns {})
322
+ client2 := NewSubResourceClient (client1 , SubResourceInterceptorFns {})
322
323
_ = client2 .Patch (ctx , nil , nil )
323
324
Expect (called ).To (BeTrue ())
324
325
})
325
326
It ("should call the provided Create function" , func () {
326
327
var called bool
327
- client := SubResourceInterceptor (srClient , SubResourceInterceptorFns {
328
+ client := NewSubResourceClient (srClient , SubResourceInterceptorFns {
328
329
Create : func (ctx context.Context , client client.SubResourceClient , obj client.Object , subResource client.Object , opts ... client.SubResourceCreateOption ) error {
329
330
called = true
330
331
return nil
@@ -335,13 +336,13 @@ var _ = Describe("SubResourceInterceptor", func() {
335
336
})
336
337
It ("should call the underlying client if the provided Create function is nil" , func () {
337
338
var called bool
338
- client1 := SubResourceInterceptor (srClient , SubResourceInterceptorFns {
339
+ client1 := NewSubResourceClient (srClient , SubResourceInterceptorFns {
339
340
Create : func (ctx context.Context , client client.SubResourceClient , obj client.Object , subResource client.Object , opts ... client.SubResourceCreateOption ) error {
340
341
called = true
341
342
return nil
342
343
},
343
344
})
344
- client2 := SubResourceInterceptor (client1 , SubResourceInterceptorFns {})
345
+ client2 := NewSubResourceClient (client1 , SubResourceInterceptorFns {})
345
346
_ = client2 .Create (ctx , nil , nil )
346
347
Expect (called ).To (BeTrue ())
347
348
})
0 commit comments