mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
test: Watch should fail immediately on negotiate errors
Instead of returning an error on the watch stream, if we can't properly negotiate a watch serialization format we should error and return that error to the client.
This commit is contained in:
parent
93868cb413
commit
9aad6aa54d
@ -34,7 +34,6 @@ import (
|
|||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
@ -659,38 +658,20 @@ func TestWatchHTTPDynamicClientErrors(t *testing.T) {
|
|||||||
watchServer.ServeHTTP(w, req)
|
watchServer.ServeHTTP(w, req)
|
||||||
}))
|
}))
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
defer s.CloseClientConnections()
|
||||||
|
|
||||||
client := dynamic.NewForConfigOrDie(&restclient.Config{
|
client := dynamic.NewForConfigOrDie(&restclient.Config{
|
||||||
Host: s.URL,
|
Host: s.URL,
|
||||||
APIPath: "/" + prefix,
|
APIPath: "/" + prefix,
|
||||||
}).Resource(newGroupVersion.WithResource("simple"))
|
}).Resource(newGroupVersion.WithResource("simple"))
|
||||||
|
|
||||||
w, err := client.Watch(metav1.ListOptions{})
|
_, err := client.Watch(metav1.ListOptions{})
|
||||||
if err != nil {
|
if err == nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if err.Error() != "no stream serializers registered for testcase/json" {
|
||||||
errStatus := errors.NewInternalError(fmt.Errorf("we got an error")).Status()
|
t.Fatalf("unexpected error: %v", err)
|
||||||
watcher.Error(&errStatus)
|
|
||||||
watcher.Stop()
|
|
||||||
|
|
||||||
got := <-w.ResultChan()
|
|
||||||
if got.Type != watch.Error {
|
|
||||||
t.Fatalf("unexpected watch type: %#v", got)
|
|
||||||
}
|
}
|
||||||
obj, ok := got.Object.(*unstructured.Unstructured)
|
|
||||||
if !ok {
|
|
||||||
t.Fatalf("not the correct object type: %#v", got)
|
|
||||||
}
|
|
||||||
|
|
||||||
status := &metav1.Status{}
|
|
||||||
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), status); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if status.Kind != "Status" || status.APIVersion != "v1" || status.Code != 500 || status.Status != "Failure" || !strings.Contains(status.Message, "we got an error") {
|
|
||||||
t.Fatalf("error: %#v", status)
|
|
||||||
}
|
|
||||||
t.Logf("status: %#v", status)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchHTTPTimeout(t *testing.T) {
|
func TestWatchHTTPTimeout(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user