Repository: kubernetes/kubernetes
File: staging/src/k8s.io/client-go/tools/cache/controller_test.go (Go)

Code before:
			Errors:            errs,
		}
	}
	m.succeedCount = len(txns)
	return nil
}

func TestReplaceEvents(t *testing.T) {
	_, ctx := ktesting.NewTestContext(t)
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	// Test that both atomic and non-atomic replace have the same behavior
	// in regards to events and store state.
	for _, atomic := range []bool{false, true} {
		source := fcache.NewFakeControllerSource()
		t.Cleanup(func() {
			source.Shutdown()
		})
		store := NewStore(DeletionHandlingMetaNamespaceKeyFunc)
		fifoOptions := RealFIFOOptions{
			KnownObjects: store,
			AtomicEvents: atomic,
		}
		if atomic {
			fifoOptions.KnownObjects = nil
		}
		fifo := NewRealFIFOWithOptions(fifoOptions)
		recorder := newEventRecorder(store)

		cfg := &Config{
			Queue:            fifo,
			ListerWatcher:    source,
			ObjectType:       &v1.Pod{},
			FullResyncPeriod: 0,

			Process: func(obj interface{}, isInInitialList bool) error {
				if deltas, ok := obj.(Deltas); ok {
					return processDeltas(recorder, store, deltas, isInInitialList, DeletionHandlingMetaNamespaceKeyFunc)
				}
				return errors.New("object given as Process argument is not Deltas")
			},
			ProcessBatch: func(deltaList []Delta, isInInitialList bool) error {
				return processDeltasInBatch(recorder, store, deltaList, isInInitialList, DeletionHandlingMetaNamespaceKeyFunc)
			},
		}
		c := New(cfg)
		go c.RunWithContext(ctx)
		if !WaitForCacheSync(ctx.Done(), c.HasSynced) {
			t.Fatal("Timed out waiting for cache sync")
		}
		testReplaceEvents(t, ctx, fifo, recorder, store, atomic)

Review comment (suggestion):
same thing here for mutually exclusive options instead of `nil`-ing out

Code after:
			SuccessfulIndices: successfuls,
			Errors:            errs,
		}
	}
	m.succeedCount = len(txns)
	return nil
}

func TestReplaceEvents(t *testing.T) {
	_, ctx := ktesting.NewTestContext(t)
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	// Test that both atomic and non-atomic replace have the same behavior
	// in regards to events and store state.
	for _, atomic := range []bool{false, true} {
		source := fcache.NewFakeControllerSource()
		t.Cleanup(func() {
			source.Shutdown()
		})
		store := NewStore(DeletionHandlingMetaNamespaceKeyFunc)
		fifoOptions := RealFIFOOptions{
			AtomicEvents: atomic,
		}
		if !atomic {
			fifoOptions.KnownObjects = store
		}
		fifo := NewRealFIFOWithOptions(fifoOptions)
		recorder := newEventRecorder(store)

		cfg := &Config{
			Queue:            fifo,
			ListerWatcher:    source,
			ObjectType:       &v1.Pod{},
			FullResyncPeriod: 0,

			Process: func(obj interface{}, isInInitialList bool) error {
				if deltas, ok := obj.(Deltas); ok {
					return processDeltas(recorder, store, deltas, isInInitialList, DeletionHandlingMetaNamespaceKeyFunc)
				}
				return errors.New("object given as Process argument is not Deltas")
			},
			ProcessBatch: func(deltaList []Delta, isInInitialList bool) error {
				return processDeltasInBatch(recorder, store, deltaList, isInInitialList, DeletionHandlingMetaNamespaceKeyFunc)
			},
		}
		c := New(cfg)
		go c.RunWithContext(ctx)
		if !WaitForCacheSync(ctx.Done(), c.HasSynced) {
			t.Fatal("Timed out waiting for cache sync")
		}
		testReplaceEvents(t, ctx, fifo, recorder, store, atomic)