Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type ClientBuilder struct {
interceptorFuncs *interceptor.Funcs
typeConverters []managedfields.TypeConverter
returnManagedFields bool
isBuilt bool

// indexes maps each GroupVersionKind (GVK) to the indexes registered for that GVK.
// The inner map maps from index name to IndexerFunc.
Expand Down Expand Up @@ -267,6 +268,9 @@ func (f *ClientBuilder) WithReturnManagedFields() *ClientBuilder {

// Build builds and returns a new fake client.
func (f *ClientBuilder) Build() client.WithWatch {
if f.isBuilt {
panic("Build() must not be called multiple times when creating a ClientBuilder")
}
if f.scheme == nil {
f.scheme = scheme.Scheme
}
Expand Down Expand Up @@ -344,6 +348,7 @@ func (f *ClientBuilder) Build() client.WithWatch {
result = interceptor.NewClient(result, *f.interceptorFuncs)
}

f.isBuilt = true
return result
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/client/fake/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3159,4 +3159,13 @@ var _ = Describe("Fake client builder", func() {
Expect(err).NotTo(HaveOccurred())
Expect(called).To(BeTrue())
})

It("should panic when calling build more than once", func() {
cb := NewClientBuilder()
anotherCb := cb
cb.Build()
Expect(func() {
anotherCb.Build()
}).To(Panic())
})
})