Skip to content

Commit 5253ca0

Browse files
authored
Merge pull request kubernetes#127528 from mmorel-35/testifylint/[email protected]/kubernetes
fix: enable compares rule from testifylint in module k8s.io/kubernetes
2 parents 61dbc03 + fa0e389 commit 5253ca0

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

pkg/kubelet/cm/devicemanager/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ func TestFeatureGateResourceHealthStatus(t *testing.T) {
20112011
{ID: "dev2", Health: pluginapi.Unhealthy},
20122012
})
20132013
// update chan no data
2014-
assert.Empty(t, len(testManager.update), 0)
2014+
assert.Empty(t, testManager.update)
20152015

20162016
// update chan receive pod1
20172017
var wg sync.WaitGroup

pkg/kubelet/container/cache_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestCacheNotInitialized(t *testing.T) {
3535
cache := newTestCache()
3636
// If the global timestamp is not set, always return nil.
3737
d := cache.getIfNewerThan(types.UID("1234"), time.Time{})
38-
assert.True(t, d == nil, "should return nil since cache is not initialized")
38+
assert.Nil(t, d, "should return nil since cache is not initialized")
3939
}
4040

4141
func getTestPodIDAndStatus(numContainers int) (types.UID, *PodStatus) {
@@ -178,9 +178,9 @@ func TestDelete(t *testing.T) {
178178

179179
func verifyNotification(t *testing.T, ch chan *data, expectNotification bool) {
180180
if expectNotification {
181-
assert.True(t, len(ch) > 0, "Did not receive notification")
181+
assert.NotEmpty(t, ch, "Did not receive notification")
182182
} else {
183-
assert.True(t, len(ch) < 1, "Should not have triggered the notification")
183+
assert.Empty(t, ch, "Should not have triggered the notification")
184184
}
185185
// Drain the channel.
186186
for i := 0; i < len(ch); i++ {

pkg/kubelet/kubelet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ func TestHandlePodCleanupsPerQOS(t *testing.T) {
527527
// done within a goroutine and can get called multiple times, so the
528528
// Destroy() count in not deterministic on the actual number.
529529
// https://github.com/kubernetes/kubernetes/blob/29fdbb065b5e0d195299eb2d260b975cbc554673/pkg/kubelet/kubelet_pods.go#L2006
530-
assert.True(t, destroyCount >= 1, "Expect 1 or more destroys")
530+
assert.GreaterOrEqual(t, destroyCount, 1, "Expect 1 or more destroys")
531531
}
532532

533533
func TestDispatchWorkOfCompletedPod(t *testing.T) {

pkg/kubelet/kubelet_volumes_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func TestVolumeAttachAndMountControllerDisabled(t *testing.T) {
390390
for _, name := range expectedPodVolumes {
391391
assert.Contains(t, podVolumes, name, "Volumes for pod %+v", pod)
392392
}
393-
assert.True(t, testKubelet.volumePlugin.GetNewAttacherCallCount() >= 1, "Expected plugin NewAttacher to be called at least once")
393+
assert.GreaterOrEqual(t, testKubelet.volumePlugin.GetNewAttacherCallCount(), 1, "Expected plugin NewAttacher to be called at least once")
394394
assert.NoError(t, volumetest.VerifyWaitForAttachCallCount(
395395
1 /* expectedWaitForAttachCallCount */, testKubelet.volumePlugin))
396396
assert.NoError(t, volumetest.VerifyAttachCallCount(
@@ -454,7 +454,7 @@ func TestVolumeUnmountAndDetachControllerDisabled(t *testing.T) {
454454
assert.Contains(t, podVolumes, name, "Volumes for pod %+v", pod)
455455
}
456456

457-
assert.True(t, testKubelet.volumePlugin.GetNewAttacherCallCount() >= 1, "Expected plugin NewAttacher to be called at least once")
457+
assert.GreaterOrEqual(t, testKubelet.volumePlugin.GetNewAttacherCallCount(), 1, "Expected plugin NewAttacher to be called at least once")
458458
assert.NoError(t, volumetest.VerifyWaitForAttachCallCount(
459459
1 /* expectedWaitForAttachCallCount */, testKubelet.volumePlugin))
460460
assert.NoError(t, volumetest.VerifyAttachCallCount(
@@ -486,7 +486,7 @@ func TestVolumeUnmountAndDetachControllerDisabled(t *testing.T) {
486486

487487
// Verify volumes detached and no longer reported as in use
488488
assert.NoError(t, waitForVolumeDetach(v1.UniqueVolumeName("fake/fake-device"), kubelet.volumeManager))
489-
assert.True(t, testKubelet.volumePlugin.GetNewAttacherCallCount() >= 1, "Expected plugin NewAttacher to be called at least once")
489+
assert.GreaterOrEqual(t, testKubelet.volumePlugin.GetNewAttacherCallCount(), 1, "Expected plugin NewAttacher to be called at least once")
490490
assert.NoError(t, volumetest.VerifyDetachCallCount(
491491
1 /* expectedDetachCallCount */, testKubelet.volumePlugin))
492492
}
@@ -566,7 +566,7 @@ func TestVolumeAttachAndMountControllerEnabled(t *testing.T) {
566566
for _, name := range expectedPodVolumes {
567567
assert.Contains(t, podVolumes, name, "Volumes for pod %+v", pod)
568568
}
569-
assert.True(t, testKubelet.volumePlugin.GetNewAttacherCallCount() >= 1, "Expected plugin NewAttacher to be called at least once")
569+
assert.GreaterOrEqual(t, testKubelet.volumePlugin.GetNewAttacherCallCount(), 1, "Expected plugin NewAttacher to be called at least once")
570570
assert.NoError(t, volumetest.VerifyWaitForAttachCallCount(
571571
1 /* expectedWaitForAttachCallCount */, testKubelet.volumePlugin))
572572
assert.NoError(t, volumetest.VerifyZeroAttachCalls(testKubelet.volumePlugin))
@@ -654,7 +654,7 @@ func TestVolumeUnmountAndDetachControllerEnabled(t *testing.T) {
654654
assert.Contains(t, podVolumes, name, "Volumes for pod %+v", pod)
655655
}
656656

657-
assert.True(t, testKubelet.volumePlugin.GetNewAttacherCallCount() >= 1, "Expected plugin NewAttacher to be called at least once")
657+
assert.GreaterOrEqual(t, testKubelet.volumePlugin.GetNewAttacherCallCount(), 1, "Expected plugin NewAttacher to be called at least once")
658658
assert.NoError(t, volumetest.VerifyWaitForAttachCallCount(
659659
1 /* expectedWaitForAttachCallCount */, testKubelet.volumePlugin))
660660
assert.NoError(t, volumetest.VerifyZeroAttachCalls(testKubelet.volumePlugin))
@@ -684,7 +684,7 @@ func TestVolumeUnmountAndDetachControllerEnabled(t *testing.T) {
684684

685685
// Verify volumes detached and no longer reported as in use
686686
assert.NoError(t, waitForVolumeDetach(v1.UniqueVolumeName("fake/fake-device"), kubelet.volumeManager))
687-
assert.True(t, testKubelet.volumePlugin.GetNewAttacherCallCount() >= 1, "Expected plugin NewAttacher to be called at least once")
687+
assert.GreaterOrEqual(t, testKubelet.volumePlugin.GetNewAttacherCallCount(), 1, "Expected plugin NewAttacher to be called at least once")
688688
assert.NoError(t, volumetest.VerifyZeroDetachCallCount(testKubelet.volumePlugin))
689689
}
690690

pkg/kubelet/prober/results/results_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func TestCacheOperations(t *testing.T) {
3939

4040
m.Set(setID, Success, &corev1.Pod{})
4141
result, found := m.Get(setID)
42-
assert.True(t, result == Success, "set result")
42+
assert.Equal(t, Success, result, "set result")
4343
assert.True(t, found, "set result found")
4444

4545
m.Remove(setID)

pkg/kubelet/status/status_manager_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,10 @@ func TestTerminatePod(t *testing.T) {
683683
t.Logf("we expect the container statuses to have changed to terminated")
684684
newStatus := expectPodStatus(t, syncer, testPod)
685685
for i := range newStatus.ContainerStatuses {
686-
assert.False(t, newStatus.ContainerStatuses[i].State.Terminated == nil, "expected containers to be terminated")
686+
assert.NotNil(t, newStatus.ContainerStatuses[i].State.Terminated, "expected containers to be terminated")
687687
}
688688
for i := range newStatus.InitContainerStatuses {
689-
assert.False(t, newStatus.InitContainerStatuses[i].State.Terminated == nil, "expected init containers to be terminated")
689+
assert.NotNil(t, newStatus.InitContainerStatuses[i].State.Terminated, "expected init containers to be terminated")
690690
}
691691

692692
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: kubecontainer.ContainerReasonStatusUnknown, Message: "The container could not be located when the pod was terminated", ExitCode: 137}}
@@ -765,13 +765,13 @@ func TestTerminatePodWaiting(t *testing.T) {
765765
t.Logf("we expect the container statuses to have changed to terminated")
766766
newStatus := expectPodStatus(t, syncer, testPod)
767767
for _, container := range newStatus.ContainerStatuses {
768-
assert.False(t, container.State.Terminated == nil, "expected containers to be terminated")
768+
assert.NotNil(t, container.State.Terminated, "expected containers to be terminated")
769769
}
770770
for _, container := range newStatus.InitContainerStatuses[:2] {
771-
assert.False(t, container.State.Terminated == nil, "expected init containers to be terminated")
771+
assert.NotNil(t, container.State.Terminated, "expected init containers to be terminated")
772772
}
773773
for _, container := range newStatus.InitContainerStatuses[2:] {
774-
assert.False(t, container.State.Waiting == nil, "expected init containers to be waiting")
774+
assert.NotNil(t, container.State.Waiting, "expected init containers to be waiting")
775775
}
776776

777777
expectUnknownState := v1.ContainerState{Terminated: &v1.ContainerStateTerminated{Reason: kubecontainer.ContainerReasonStatusUnknown, Message: "The container could not be located when the pod was terminated", ExitCode: 137}}

pkg/kubelet/userns/userns_manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ func TestUserNsManagerAllocate(t *testing.T) {
122122
allocated, length, err = m.allocateOne(types.UID(fmt.Sprintf("%d", i)))
123123
assert.Equal(t, userNsLength, int(length), "length is not the expected. iter: %v", i)
124124
assert.NoError(t, err)
125-
assert.True(t, allocated >= minimumMappingUID)
125+
assert.GreaterOrEqual(t, allocated, uint32(minimumMappingUID))
126126
// The last ID of the userns range (allocated+userNsLength) should be within bounds.
127-
assert.True(t, allocated <= minimumMappingUID+mappingLen-userNsLength)
127+
assert.LessOrEqual(t, allocated, uint32(minimumMappingUID+mappingLen-userNsLength))
128128
allocs = append(allocs, allocated)
129129
}
130130
for i, v := range allocs {

0 commit comments

Comments
 (0)