@@ -28,6 +28,8 @@ import (
28
28
"strings"
29
29
"sync"
30
30
31
+ "sigs.k8s.io/controller-runtime/pkg/client/interceptor"
32
+
31
33
apierrors "k8s.io/apimachinery/pkg/api/errors"
32
34
"k8s.io/apimachinery/pkg/api/meta"
33
35
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -107,6 +109,7 @@ type ClientBuilder struct {
107
109
initRuntimeObjects []runtime.Object
108
110
withStatusSubresource []client.Object
109
111
objectTracker testing.ObjectTracker
112
+ interceptorFns * interceptor.Fns
110
113
111
114
// indexes maps each GroupVersionKind (GVK) to the indexes registered for that GVK.
112
115
// The inner map maps from index name to IndexerFunc.
@@ -198,6 +201,12 @@ func (f *ClientBuilder) WithStatusSubresource(o ...client.Object) *ClientBuilder
198
201
return f
199
202
}
200
203
204
+ // WithInterceptorFns configures the client methods to be intercepted using the provided interceptor.Fns.
205
+ func (f * ClientBuilder ) WithInterceptorFns (interceptorFns interceptor.Fns ) * ClientBuilder {
206
+ f .interceptorFns = & interceptorFns
207
+ return f
208
+ }
209
+
201
210
// Build builds and returns a new fake client.
202
211
func (f * ClientBuilder ) Build () client.WithWatch {
203
212
if f .scheme == nil {
@@ -240,13 +249,19 @@ func (f *ClientBuilder) Build() client.WithWatch {
240
249
}
241
250
}
242
251
243
- return & fakeClient {
252
+ var result client. WithWatch = & fakeClient {
244
253
tracker : tracker ,
245
254
scheme : f .scheme ,
246
255
restMapper : f .restMapper ,
247
256
indexes : f .indexes ,
248
257
withStatusSubresource : withStatusSubResource ,
249
258
}
259
+
260
+ if f .interceptorFns != nil {
261
+ result = interceptor .NewClient (result , * f .interceptorFns )
262
+ }
263
+
264
+ return result
250
265
}
251
266
252
267
const trackerAddResourceVersion = "999"
0 commit comments