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
- client-go: properly return error in fake discovery (#79612) Fake discovery should return an error if an error-returning reactor was prepended. This is relevant e.g. for unit tests which test a funct... — committed to MaxHorstmann/kubernetes by MaxHorstmann 2 years ago
- Merge pull request #114291 from MaxHorstmann/master #79612 fix(client-go): return error in fake discovery — committed to kubernetes/kubernetes by k8s-ci-robot 2 years ago
- client-go: properly return error in fake discovery (#79612) Fake discovery should return an error if an error-returning reactor was prepended. This is relevant e.g. for unit tests which test a funct... — committed to jaehnri/kubernetes by MaxHorstmann 2 years ago
I submited a PR #86770 to fix this issue. PTAL @alejandrox1 .