From 50eed81923495f5ee1ac44436676ddbaf2a380fe Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Thu, 17 Feb 2022 15:46:05 -0800 Subject: [PATCH] storage: etcd: TestWatchError: improve readability This test, as written, is *extremely* cryptic and hard to parse. Add a comment and stop intentionally ignoring an error that only needs to be ignored if we're being cryptic. Signed-off-by: Steve Kuznetsov --- .../apiserver/pkg/storage/etcd3/watcher_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/watcher_test.go b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/watcher_test.go index 3f55398dd7f..f94f452e6b1 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/etcd3/watcher_test.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/etcd3/watcher_test.go @@ -26,7 +26,7 @@ import ( clientv3 "go.etcd.io/etcd/client/v3" - apitesting "k8s.io/apimachinery/pkg/api/apitesting" + "k8s.io/apimachinery/pkg/api/apitesting" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" @@ -216,19 +216,23 @@ func TestWatchFromNoneZero(t *testing.T) { } func TestWatchError(t *testing.T) { - codec := &testCodec{apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion)} + // this codec fails on decodes, which will bubble up so we can verify the behavior + invalidCodec := &testCodec{apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion)} client := testserver.RunEtcd(t, nil) - invalidStore := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte("test!")}, true, NewDefaultLeaseManagerConfig()) + invalidStore := newStore(client, invalidCodec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte("test!")}, true, NewDefaultLeaseManagerConfig()) ctx := context.Background() w, err := invalidStore.Watch(ctx, "/abc", storage.ListOptions{ResourceVersion: "0", Predicate: storage.Everything}) if err != nil { t.Fatalf("Watch failed: %v", err) } + codec := apitesting.TestCodec(codecs, examplev1.SchemeGroupVersion) validStore := newStore(client, codec, newPod, "", schema.GroupResource{Resource: "pods"}, &prefixTransformer{prefix: []byte("test!")}, true, NewDefaultLeaseManagerConfig()) - validStore.GuaranteedUpdate(ctx, "/abc", &example.Pod{}, true, nil, storage.SimpleUpdate( + if err := validStore.GuaranteedUpdate(ctx, "/abc", &example.Pod{}, true, nil, storage.SimpleUpdate( func(runtime.Object) (runtime.Object, error) { return &example.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}, nil - }), nil) + }), nil); err != nil { + t.Fatalf("GuaranteedUpdate failed: %v", err) + } testCheckEventType(t, watch.Error, w) }