Change:
I'm writing a UT for the following function: The code branch where the server returns an error other than could not be tested using 's . This is because does not handle the error returned by and therefore could not return errors other than : Ref: Add a to so simulate errors other than . Run the following UT (should fail):
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the label and provide further guidance. The label can be by org members by writing in a comment. <detailsInstructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/sig api-machinery
Same issue for some other methods of : -
I'll submit a PR shortly to address this issue. /assign

Discussion:
Verb:     "get", Resource: schema.GroupVersionResource{Resource: "resource"}, } <del> c.Invokes(action, nil) </del> <ins> if _, err := c.Invokes(action, nil); err != nil { return nil, err } </ins> for _, resourceList := range c.Resources { if resourceList.GroupVersion == groupVersion { return resourceList, nil

Verb:     "get", Resource: schema.GroupVersionResource{Resource: "resource"}, } <del> c.Invokes(action, nil) </del> <ins> if _, err = c.Invokes(action, nil); err != nil { return resultGroups, c.Resources, err } </ins> return resultGroups, c.Resources, nil }

Verb:     "get", Resource: schema.GroupVersionResource{Resource: "group"}, } <del> c.Invokes(action, nil) </del> <ins> if _, err := c.Invokes(action, nil); err != nil { return nil, err } </ins> groups := map[string]*metav1.APIGroup{}

t.Fatal("ServerVersion should return expected error, returned different error instead") } } <ins> func TestFakingServerResourcesForGroupVersionWithError(t *testing.T) { expectedError := errors.New("an error occurred") fakeClient := fakeclientset.NewClientset() fakeClient.Discovery().(*fakediscovery.FakeDiscovery).PrependReactor("*", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { return true, nil, expectedError }) result, err := fakeClient.Discovery().ServerResourcesForGroupVersion("dummy.group.io/v1beta2") if result != nil { t.Errorf(`expect result to be nil but got "%v" instead`, result) } if !errors.Is(err, expectedError) { t.Errorf(`expect error to be "%v" but got "%v" instead`, expectedError, err) } } func TestFakingServerGroupsWithError(t *testing.T) { expectedError := errors.New("an error occurred") fakeClient := fakeclientset.NewClientset() fakeClient.Discovery().(*fakediscovery.FakeDiscovery).PrependReactor("*", "*", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { return true, nil, expectedError }) result, err := fakeClient.Discovery().ServerGroups() if result != nil { t.Errorf(`expect result to be nil but got "%v" instead`, result) } if !errors.Is(err, expectedError) { t.Errorf(`expect error to be "%v" but got "%v" instead`, expectedError, err) } } func TestFakingServerGroupsAndResourcesWithError(t *testing.T) { expectedError := errors.New("an error occurred") fakeClient := fakeclientset.NewClientset() fakeClient.Discovery().(*fakediscovery.FakeDiscovery).PrependReactor("get", "resource", func(action kubetesting.Action) (handled bool, ret runtime.Object, err error) { return true, nil, expectedError }) _, _, err := fakeClient.Discovery().ServerGroupsAndResources() if !errors.Is(err, expectedError) { t.Errorf(`expect error to be "%v" but got "%v" instead`, expectedError, err) } } </ins>