Repository: kubernetes/kubernetes
File: pkg/kubelet/kubelet_test.go (Go)

Code before:
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NodeDeclaredFeatures, tc.featureGateEnabled)

			testKubelet := newTestKubelet(t, false)
			defer testKubelet.Cleanup()
			kubelet := testKubelet.kubelet

			// Setup mocks
			recorder := record.NewFakeRecorder(10)
			kubelet.recorder = recorder

			framework, err := ndf.New(tc.registeredFeatures)
			require.NoError(t, err)
			kubelet.nodeDeclaredFeaturesFramework = framework
			kubelet.nodeDeclaredFeatures = tc.nodeFeatures
			kubelet.nodeDeclaredFeaturesSet = ndf.NewFeatureSet(kubelet.nodeDeclaredFeatures...)
			kubelet.version = utilversion.MustParse("1.35.0")

			if tc.oldPod != nil {
				kubelet.podManager.SetPods([]*v1.Pod{tc.oldPod})
			}

			kubelet.statusManager.SetPodStatus(klog.TODO(), tc.newPod, v1.PodStatus{Phase: v1.PodRunning})
			kubelet.HandlePodUpdates(ctx, []*v1.Pod{tc.newPod})
			if tc.expectEvent {
				select {
				case event := <-recorder.Events:
					assert.Contains(t, event, tc.expectedEventMsg)
				default:
					t.Errorf("Expected an event but did not receive one.")
				}
			} else {
				select {
				case event := <-recorder.Events:
					t.Errorf("Expected no event, but received: %s", event)
				default:
					// No event received, which is correct.
				}
			}
		})
	}
}


Review comment (suggestion):
```suggestion
			kubelet.statusManager.SetPodStatus(logger, tc.newPod, v1.PodStatus{Phase: v1.PodRunning})
```

and the same everywhere in this file where TODO and Background calls are used.

Code after:
			registeredFeatures: []ndf.Feature{createMockFeature(t, "FeatureA", true, "")},
			expectEvent:        false,
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			logger := klog.FromContext(ctx)
			featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NodeDeclaredFeatures, tc.featureGateEnabled)

			testKubelet := newTestKubelet(t, false)
			defer testKubelet.Cleanup()
			kubelet := testKubelet.kubelet

			// Setup mocks
			recorder := record.NewFakeRecorder(10)
			kubelet.recorder = recorder

			framework, err := ndf.New(tc.registeredFeatures)
			require.NoError(t, err)
			kubelet.nodeDeclaredFeaturesFramework = framework
			kubelet.nodeDeclaredFeatures = tc.nodeFeatures
			kubelet.nodeDeclaredFeaturesSet = ndf.NewFeatureSet(kubelet.nodeDeclaredFeatures...)
			kubelet.version = utilversion.MustParse("1.35.0")

			if tc.oldPod != nil {
				kubelet.podManager.SetPods([]*v1.Pod{tc.oldPod})
			}

			kubelet.statusManager.SetPodStatus(logger, tc.newPod, v1.PodStatus{Phase: v1.PodRunning})
			kubelet.HandlePodUpdates(ctx, []*v1.Pod{tc.newPod})
			if tc.expectEvent {
				select {
				case event := <-recorder.Events:
					assert.Contains(t, event, tc.expectedEventMsg)
				default:
					t.Errorf("Expected an event but did not receive one.")
				}
			} else {
				select {
				case event := <-recorder.Events:
					t.Errorf("Expected no event, but received: %s", event)
				default:
					// No event received, which is correct.
				}
			}
		})
	}
}