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 {
141141	interceptorFuncs       * interceptor.Funcs 
142142	typeConverters         []managedfields.TypeConverter 
143143	returnManagedFields    bool 
144+ 	isBuilt                bool 
144145
145146	// indexes maps each GroupVersionKind (GVK) to the indexes registered for that GVK. 
146147	// The inner map maps from index name to IndexerFunc. 
@@ -267,6 +268,9 @@ func (f *ClientBuilder) WithReturnManagedFields() *ClientBuilder {
267268
268269// Build builds and returns a new fake client. 
269270func  (f  * ClientBuilder ) Build () client.WithWatch  {
271+ 	if  f .isBuilt  {
272+ 		panic ("Build() must not be called multiple times when creating a ClientBuilder" )
273+ 	}
270274	if  f .scheme  ==  nil  {
271275		f .scheme  =  scheme .Scheme 
272276	}
@@ -344,6 +348,7 @@ func (f *ClientBuilder) Build() client.WithWatch {
344348		result  =  interceptor .NewClient (result , * f .interceptorFuncs )
345349	}
346350
351+ 	f .isBuilt  =  true 
347352	return  result 
348353}
349354
Original file line number Diff line number Diff line change @@ -3159,4 +3159,13 @@ var _ = Describe("Fake client builder", func() {
31593159		Expect (err ).NotTo (HaveOccurred ())
31603160		Expect (called ).To (BeTrue ())
31613161	})
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+ 	})
31623171})
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments