@@ -408,7 +408,7 @@ func TestListBindingsFromKey(t *testing.T) {
408408 WithObjects (tt .objects ... ).
409409 Build ()
410410
411- got , err := ListBindingsFromKey (ctx , fakeClient , tt .placementKey )
411+ got , err := ListBindingsFromKey (ctx , fakeClient , tt .placementKey , true )
412412
413413 if tt .wantErr {
414414 if err == nil {
@@ -498,13 +498,13 @@ func TestListBindingsFromKey_Sorted(t *testing.T) {
498498 },
499499 }
500500
501- bindingsInMode0 , err := ListBindingsFromKey (ctx , & mockClient , types.NamespacedName {Name : "placeholder" })
501+ bindingsInMode0 , err := ListBindingsFromKey (ctx , & mockClient , types.NamespacedName {Name : "placeholder" }, true )
502502 if err != nil {
503503 t .Fatalf ("ListBindingsFromKey() in mode 0 returned error: %v" , err )
504504 }
505505
506506 mockMode .Store (1 )
507- bindingsInMode1 , err := ListBindingsFromKey (ctx , & mockClient , types.NamespacedName {Name : "placeholder" })
507+ bindingsInMode1 , err := ListBindingsFromKey (ctx , & mockClient , types.NamespacedName {Name : "placeholder" }, true )
508508 if err != nil {
509509 t .Fatalf ("ListBindingsFromKey() in mode 1 returned error: %v" , err )
510510 }
@@ -517,23 +517,42 @@ func TestListBindingsFromKey_Sorted(t *testing.T) {
517517func TestListBindingsFromKey_ClientError (t * testing.T ) {
518518 ctx := context .Background ()
519519
520- // Create a client that will return an error
521- scheme := runtime .NewScheme ()
522- _ = placementv1beta1 .AddToScheme (scheme )
523-
524- // Use a fake client but override List to return error
525- fakeClient := & failingListClient {
526- Client : fake .NewClientBuilder ().WithScheme (scheme ).Build (),
520+ tests := []struct {
521+ name string
522+ fromCache bool
523+ wantErr error
524+ }{
525+ {
526+ name : "uncached client returns ErrAPIServerError" ,
527+ fromCache : false ,
528+ wantErr : ErrAPIServerError ,
529+ },
530+ {
531+ name : "cached client returns ErrUnexpectedBehavior as cached List should not fail" ,
532+ fromCache : true ,
533+ wantErr : ErrUnexpectedBehavior ,
534+ },
527535 }
528536
529- _ , err := ListBindingsFromKey (ctx , fakeClient , types.NamespacedName {Name : "test-placement" })
537+ for _ , tt := range tests {
538+ t .Run (tt .name , func (t * testing.T ) {
539+ // Create a client that will return an error
540+ scheme := runtime .NewScheme ()
541+ _ = placementv1beta1 .AddToScheme (scheme )
530542
531- if err == nil {
532- t .Fatalf ("Expected error but got nil" )
533- }
543+ // Use a fake client but override List to return error
544+ fakeClient := & failingListClient {
545+ Client : fake .NewClientBuilder ().WithScheme (scheme ).Build (),
546+ }
534547
535- if ! errors .Is (err , ErrAPIServerError ) {
536- t .Errorf ("Expected ErrAPIServerError but got: %v" , err )
548+ _ , err := ListBindingsFromKey (ctx , fakeClient , types.NamespacedName {Name : "test-placement" }, tt .fromCache )
549+ if err == nil {
550+ t .Fatalf ("Expected error but got nil" )
551+ }
552+ if ! errors .Is (err , tt .wantErr ) {
553+ t .Errorf ("Expected %v but got: %v" , tt .wantErr , err )
554+ }
555+ })
537556 }
538557}
539558
0 commit comments