Skip to content

Commit

Permalink
[CI] Enable testifylint empty rule (#2908)
Browse files Browse the repository at this point in the history
  • Loading branch information
400Ping authored Feb 5, 2025
1 parent 2ac2a92 commit 00abf6e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ linters-settings:
- bool-compare
- len
- compares
- empty
linters:
enable:
- asciicheck
Expand Down
2 changes: 1 addition & 1 deletion ray-operator/controllers/ray/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ func TestDefaultInitContainer(t *testing.T) {
healthCheckContainer := podTemplateSpec.Spec.InitContainers[numInitContainers-1]
rayContainer := worker.Template.Spec.Containers[utils.RayContainerIndex]

assert.NotEqual(t, len(rayContainer.Env), 0, "The test only makes sense if the Ray container has environment variables.")
assert.NotEmpty(t, rayContainer.Env, "The test only makes sense if the Ray container has environment variables.")
assert.Equal(t, len(rayContainer.Env), len(healthCheckContainer.Env))
for _, env := range rayContainer.Env {
// env.ValueFrom is the source for the environment variable's value. Cannot be used if value is not empty.
Expand Down
22 changes: 11 additions & 11 deletions ray-operator/controllers/ray/raycluster_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,8 @@ func TestReconcile_PodEvicted_DiffLess0_OK(t *testing.T) {
})

assert.NoError(t, err, "Fail to get pod list after reconcile")
assert.Equal(t, 0, len(podList.Items),
"Evicted head should be deleted after reconcile expect %d actual %d", 0, len(podList.Items))
assert.Empty(t, podList.Items,
"Evicted head should be deleted after reconcile. Actual number of items: %d", len(podList.Items))
})
}
}
Expand Down Expand Up @@ -2420,7 +2420,7 @@ func Test_TerminatedHead_RestartPolicy(t *testing.T) {
assert.Error(t, err)
err = fakeClient.List(ctx, &podList, client.InNamespace(namespaceStr))
assert.NoError(t, err, "Fail to get pod list")
assert.Equal(t, 0, len(podList.Items))
assert.Empty(t, podList.Items)

// The new head Pod will be created in this reconcile loop.
err = testRayClusterReconciler.reconcilePods(ctx, cluster)
Expand Down Expand Up @@ -2450,7 +2450,7 @@ func Test_TerminatedHead_RestartPolicy(t *testing.T) {
assert.Error(t, err)
err = fakeClient.List(ctx, &podList, client.InNamespace(namespaceStr))
assert.NoError(t, err, "Fail to get pod list")
assert.Equal(t, 0, len(podList.Items))
assert.Empty(t, podList.Items)

// The new head Pod will be created in this reconcile loop.
err = testRayClusterReconciler.reconcilePods(ctx, cluster)
Expand Down Expand Up @@ -2519,7 +2519,7 @@ func Test_RunningPods_RayContainerTerminated(t *testing.T) {
assert.Error(t, err)
err = fakeClient.List(ctx, &podList, client.InNamespace(namespaceStr))
assert.NoError(t, err, "Fail to get pod list")
assert.Equal(t, 0, len(podList.Items))
assert.Empty(t, podList.Items)

// The new head Pod will be created in this reconcile loop.
err = testRayClusterReconciler.reconcilePods(ctx, cluster)
Expand Down Expand Up @@ -2724,15 +2724,15 @@ func Test_RedisCleanupFeatureFlag(t *testing.T) {
err := fakeClient.List(ctx, &rayClusterList, client.InNamespace(namespaceStr))
assert.NoError(t, err, "Fail to get RayCluster list")
assert.Equal(t, 1, len(rayClusterList.Items))
assert.Equal(t, 0, len(rayClusterList.Items[0].Finalizers))
assert.Empty(t, rayClusterList.Items[0].Finalizers)

_, err = testRayClusterReconciler.rayClusterReconcile(ctx, cluster)
if tc.enableGCSFTRedisCleanup == "false" {
assert.NoError(t, err)
podList := corev1.PodList{}
err = fakeClient.List(ctx, &podList, client.InNamespace(namespaceStr))
assert.NoError(t, err)
assert.NotEqual(t, 0, len(podList.Items))
assert.NotEmpty(t, podList.Items)
} else {
// Add the GCS FT Redis cleanup finalizer to the RayCluster.
assert.NoError(t, err)
Expand All @@ -2751,15 +2751,15 @@ func Test_RedisCleanupFeatureFlag(t *testing.T) {
podList := corev1.PodList{}
err = fakeClient.List(ctx, &podList, client.InNamespace(namespaceStr))
assert.NoError(t, err, "Fail to get Pod list")
assert.Equal(t, 0, len(podList.Items))
assert.Empty(t, podList.Items)

// Reconcile the RayCluster again. The controller should create Pods.
_, err = testRayClusterReconciler.rayClusterReconcile(ctx, cluster)
assert.NoError(t, err)

err = fakeClient.List(ctx, &podList, client.InNamespace(namespaceStr))
assert.NoError(t, err, "Fail to get Pod list")
assert.NotEqual(t, 0, len(podList.Items))
assert.NotEmpty(t, podList.Items)
}
})
}
Expand Down Expand Up @@ -2982,7 +2982,7 @@ func Test_RedisCleanup(t *testing.T) {
jobList := batchv1.JobList{}
err := fakeClient.List(ctx, &jobList, client.InNamespace(namespaceStr))
assert.NoError(t, err, "Fail to get Job list")
assert.Equal(t, 0, len(jobList.Items))
assert.Empty(t, jobList.Items)

_, err = testRayClusterReconciler.rayClusterReconcile(ctx, cluster)
assert.NoError(t, err)
Expand Down Expand Up @@ -3015,7 +3015,7 @@ func Test_RedisCleanup(t *testing.T) {
assert.NoError(t, err, "Fail to reconcile RayCluster")
err = fakeClient.List(ctx, &rayClusterList, client.InNamespace(namespaceStr))
assert.NoError(t, err, "Fail to get RayCluster list")
assert.Equal(t, 0, len(rayClusterList.Items))
assert.Empty(t, rayClusterList.Items)
}
})
}
Expand Down

0 comments on commit 00abf6e

Please sign in to comment.