kubernetes: Could not simulate an error in discovery/fake/ServerVersion

What happened:

I was trying to write a test in a service I’m working on to catch if an error returns from client.Discovery().ServerVersion(). When I overrode the result of the fake client with a reactor to return an error I did not get the error back.

What you expected to happen: If the reactor is set to return an error, it should come back.

How to reproduce it (as minimally and precisely as possible):

func TestReturnErrorFromServerVersion(t *testing.T) {
	expectedError := errors.New("error override")
	client := fakeclientset.NewSimpleClientset()
	reactor := func(action clientTesting.Action) (handled bool, ret runtime.Object, err error) {
		return true, nil, expectedError
	}
	client.PrependReactor("get", "version", reactor)

	_, err := client.Discovery().ServerVersion()

	if err == nil {
		t.Fatal("Error did not return from read of server version")
	}

	if err.Error() != expectedError.Error() {
		t.Fatalf("unexpected error message: %s", err.Error())
	}
}

Anything else we need to know?:

This only happens with the fake.

Environment:

  • Kubernetes version (use kubectl version): 1.14
  • Cloud provider or hardware configuration: any
  • OS (e.g: cat /etc/os-release): any
  • Kernel (e.g. uname -a): any
  • Install tools: any
  • Network plugin and version (if this is a network-related bug): n/a
  • Others:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I submited a PR #86770 to fix this issue. PTAL @alejandrox1 .