diff --git a/tools/watch/informerwatcher_test.go b/tools/watch/informerwatcher_test.go index e03f9612d..07cea0023 100644 --- a/tools/watch/informerwatcher_test.go +++ b/tools/watch/informerwatcher_test.go @@ -387,7 +387,7 @@ func TestNewInformerWatcher(t *testing.T) { func TestInformerWatcherDeletedFinalStateUnknown(t *testing.T) { listCalls := 0 watchCalls := 0 - lw := &cache.ListWatch{ + lw := toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { retval := &corev1.SecretList{} if listCalls == 0 { @@ -413,7 +413,7 @@ func TestInformerWatcherDeletedFinalStateUnknown(t *testing.T) { watchCalls++ return w, nil }, - } + }) //nolint:logcheck // Intentionally uses the older API. _, _, w, done := NewIndexerInformerWatcher(lw, &corev1.Secret{}) defer w.Stop() @@ -464,3 +464,17 @@ func TestInformerWatcherDeletedFinalStateUnknown(t *testing.T) { t.Fatalf("expected at least 1 watch call, got %d", watchCalls) } } + +type listWatchWithUnSupportedWatchListSemanticsWrapper struct { + *cache.ListWatch +} + +func (lw listWatchWithUnSupportedWatchListSemanticsWrapper) IsWatchListSemanticsUnSupported() bool { + return true +} + +func toListWatcherWithUnSupportedWatchListSemantics(lw *cache.ListWatch) cache.ListerWatcher { + return listWatchWithUnSupportedWatchListSemanticsWrapper{ + lw, + } +} diff --git a/tools/watch/until_test.go b/tools/watch/until_test.go index d2194fbd0..255cf5432 100644 --- a/tools/watch/until_test.go +++ b/tools/watch/until_test.go @@ -189,7 +189,7 @@ func TestUntilWithSync(t *testing.T) { // FIXME: test preconditions tt := []struct { name string - lw *cache.ListWatch + lw cache.ListerWatcher preconditionFunc PreconditionFunc conditionFunc ConditionFunc expectedErr error @@ -197,14 +197,14 @@ func TestUntilWithSync(t *testing.T) { }{ { name: "doesn't wait for sync with no precondition", - lw: &cache.ListWatch{ + lw: toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { select {} }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { select {} }, - }, + }), preconditionFunc: nil, conditionFunc: func(e watch.Event) (bool, error) { return true, nil @@ -214,14 +214,14 @@ func TestUntilWithSync(t *testing.T) { }, { name: "waits indefinitely with precondition if it can't sync", - lw: &cache.ListWatch{ + lw: toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { select {} }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { select {} }, - }, + }), preconditionFunc: func(store cache.Store) (bool, error) { return true, nil }, @@ -233,17 +233,17 @@ func TestUntilWithSync(t *testing.T) { }, { name: "precondition can stop the loop", - lw: func() *cache.ListWatch { + lw: func() cache.ListerWatcher { fakeclient := fakeclient.NewSimpleClientset(&corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "first"}}) - return &cache.ListWatch{ + return toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { return fakeclient.CoreV1().Secrets("").List(context.TODO(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { return fakeclient.CoreV1().Secrets("").Watch(context.TODO(), options) }, - } + }) }(), preconditionFunc: func(store cache.Store) (bool, error) { _, exists, err := store.Get(&metav1.ObjectMeta{Namespace: "", Name: "first"}) @@ -263,17 +263,17 @@ func TestUntilWithSync(t *testing.T) { }, { name: "precondition lets it proceed to regular condition", - lw: func() *cache.ListWatch { + lw: func() cache.ListerWatcher { fakeclient := fakeclient.NewSimpleClientset(&corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "first"}}) - return &cache.ListWatch{ + return toListWatcherWithUnSupportedWatchListSemantics(&cache.ListWatch{ ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { return fakeclient.CoreV1().Secrets("").List(context.TODO(), options) }, WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { return fakeclient.CoreV1().Secrets("").Watch(context.TODO(), options) }, - } + }) }(), preconditionFunc: func(store cache.Store) (bool, error) { return false, nil