File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ type ClientBuilder struct {
141
141
interceptorFuncs * interceptor.Funcs
142
142
typeConverters []managedfields.TypeConverter
143
143
returnManagedFields bool
144
+ isBuilt bool
144
145
145
146
// indexes maps each GroupVersionKind (GVK) to the indexes registered for that GVK.
146
147
// The inner map maps from index name to IndexerFunc.
@@ -267,6 +268,9 @@ func (f *ClientBuilder) WithReturnManagedFields() *ClientBuilder {
267
268
268
269
// Build builds and returns a new fake client.
269
270
func (f * ClientBuilder ) Build () client.WithWatch {
271
+ if f .isBuilt {
272
+ panic ("Build() must not be called multiple times when creating a ClientBuilder" )
273
+ }
270
274
if f .scheme == nil {
271
275
f .scheme = scheme .Scheme
272
276
}
@@ -344,6 +348,7 @@ func (f *ClientBuilder) Build() client.WithWatch {
344
348
result = interceptor .NewClient (result , * f .interceptorFuncs )
345
349
}
346
350
351
+ f .isBuilt = true
347
352
return result
348
353
}
349
354
Original file line number Diff line number Diff line change @@ -3159,4 +3159,13 @@ var _ = Describe("Fake client builder", func() {
3159
3159
Expect (err ).NotTo (HaveOccurred ())
3160
3160
Expect (called ).To (BeTrue ())
3161
3161
})
3162
+
3163
+ It ("should panic when calling build more than once" , func () {
3164
+ cb := NewClientBuilder ()
3165
+ anotherCb := cb
3166
+ cb .Build ()
3167
+ Expect (func () {
3168
+ anotherCb .Build ()
3169
+ }).To (Panic ())
3170
+ })
3162
3171
})
You can’t perform that action at this time.
0 commit comments