From 0381acd2c97adf07115c4c8fe74bf26b4fe91ad6 Mon Sep 17 00:00:00 2001 From: "Nelo-T. Wallus" Date: Fri, 20 Mar 2026 08:04:40 +0100 Subject: [PATCH 1/2] Fix various testify usage issues Signed-off-by: Nelo-T. Wallus Signed-off-by: Nelo-T. Wallus --- .../topology/partitionset/partitioning_test.go | 10 +++++----- pkg/server/apiextensions_test.go | 2 +- .../apiexport/authorizer/binding_test.go | 2 +- .../maximal_permission_policy_test.go | 2 +- .../apiexport_apireconciler_controller_test.go | 2 +- .../apiexport/schemas/builtin/builtin_test.go | 2 +- test/e2e/apibinding/apibinding_deletion_test.go | 2 +- test/e2e/apibinding/apibinding_test.go | 8 ++++---- .../maximalpermissionpolicy_authorizer_test.go | 8 ++++---- test/e2e/authorizer/serviceaccounts_test.go | 4 ++-- .../apiexportendpointslice_test.go | 6 +++--- test/e2e/reconciler/cache/helpers.go | 3 ++- .../partitionset/partitionset_test.go | 4 ++-- .../workspacedeletion/controller_test.go | 4 ++-- test/e2e/server/url_test.go | 2 +- test/e2e/virtual/apiexport/binding_test.go | 2 +- .../virtual/apiexport/virtualworkspace_test.go | 12 ++++++------ .../virtualworkspace_test.go | 4 ++-- .../virtualworkspace_test.go | 6 +++--- .../cachedresources/vr_cachedresources_test.go | 8 +++----- test/e2e/watchcache/watchcache_enabled_test.go | 4 ++-- test/e2e/workspace/deletion_test.go | 4 ++-- test/e2e/workspace/inactive_test.go | 2 -- test/e2e/workspacetype/controller_test.go | 17 ++++++++--------- test/integration/framework/server_test.go | 6 +++--- 25 files changed, 61 insertions(+), 65 deletions(-) diff --git a/pkg/reconciler/topology/partitionset/partitioning_test.go b/pkg/reconciler/topology/partitionset/partitioning_test.go index fea9ba6a136..d7158d8100a 100644 --- a/pkg/reconciler/topology/partitionset/partitioning_test.go +++ b/pkg/reconciler/topology/partitionset/partitioning_test.go @@ -118,19 +118,19 @@ func TestPartition(t *testing.T) { } matchLabelsMap := partition(shards, []string{}, nil) - require.Equal(t, 0, len(matchLabelsMap), "No label selector expected when no dimension is provided, got: %v", matchLabelsMap) + require.Empty(t, matchLabelsMap, "No label selector expected when no dimension is provided, got: %v", matchLabelsMap) matchLabelsMap = partition(shards, []string{"doesnotexist"}, nil) - require.Equal(t, 0, len(matchLabelsMap), "No label selector expected when no shard with the dimension, got: %v", matchLabelsMap) + require.Empty(t, matchLabelsMap, "No label selector expected when no shard with the dimension, got: %v", matchLabelsMap) matchLabelsMap = partition(shards, []string{"region"}, nil) - require.Equal(t, 2, len(matchLabelsMap), "2 label selectors for region: Europe and Asia expected, got: %v", matchLabelsMap) + require.Len(t, matchLabelsMap, 2, "2 label selectors for region: Europe and Asia expected, got: %v", matchLabelsMap) matchLabelsMap = partition(shards, []string{"region", "cloud"}, nil) - require.Equal(t, 3, len(matchLabelsMap), "3 label selectors for: Asia/Azure, Europe/AWS and Europe/Azure expected, got: %v", matchLabelsMap) + require.Len(t, matchLabelsMap, 3, "3 label selectors for: Asia/Azure, Europe/AWS and Europe/Azure expected, got: %v", matchLabelsMap) matchLabelsMap = partition(shards, []string{"region", "cloud"}, map[string]string{"environment": "prod"}) - require.Equal(t, 3, len(matchLabelsMap), "3 label selectors for: Asia/Azure, Europe/AWS, Europe/Azure expected, got: %v", matchLabelsMap) + require.Len(t, matchLabelsMap, 3, "3 label selectors for: Asia/Azure, Europe/AWS, Europe/Azure expected, got: %v", matchLabelsMap) for _, v := range matchLabelsMap { require.Equal(t, "prod", v["environment"], "Expected that all partitions have a label selector for environment = prod") } diff --git a/pkg/server/apiextensions_test.go b/pkg/server/apiextensions_test.go index 1eff2b84bc5..696f7301321 100644 --- a/pkg/server/apiextensions_test.go +++ b/pkg/server/apiextensions_test.go @@ -32,7 +32,7 @@ import ( ) func TestSystemCRDsLogicalClusterName(t *testing.T) { - require.Equal(t, SystemCRDClusterName.String(), reservedcrdgroups.SystemCRDLogicalClusterName, "reservedcrdgroups admission check should match SystemCRDLogicalCluster") + require.Equal(t, reservedcrdgroups.SystemCRDLogicalClusterName, SystemCRDClusterName.String(), "reservedcrdgroups admission check should match SystemCRDLogicalCluster") } func TestDecorateCRDWithBinding(t *testing.T) { diff --git a/pkg/virtual/apiexport/authorizer/binding_test.go b/pkg/virtual/apiexport/authorizer/binding_test.go index 5764699b746..0e8030e49f8 100644 --- a/pkg/virtual/apiexport/authorizer/binding_test.go +++ b/pkg/virtual/apiexport/authorizer/binding_test.go @@ -712,7 +712,7 @@ func TestBoundAPIAuthorizer(t *testing.T) { if err != nil { errString = err.Error() } - require.Equal(t, errString, tc.expectedErr) + require.Equal(t, tc.expectedErr, errString) require.Equal(t, tc.expectedDecision, dec) require.Equal(t, tc.expectedReason, reason) }) diff --git a/pkg/virtual/apiexport/authorizer/maximal_permission_policy_test.go b/pkg/virtual/apiexport/authorizer/maximal_permission_policy_test.go index beceac28f0c..8677b623511 100644 --- a/pkg/virtual/apiexport/authorizer/maximal_permission_policy_test.go +++ b/pkg/virtual/apiexport/authorizer/maximal_permission_policy_test.go @@ -326,7 +326,7 @@ func TestMaximalPermissionPolicyAuthorizer(t *testing.T) { if err != nil { errString = err.Error() } - require.Equal(t, errString, tc.expectedErr) + require.Equal(t, tc.expectedErr, errString) require.Equal(t, tc.expectedDecision, dec) require.Equal(t, tc.expectedReason, reason) }) diff --git a/pkg/virtual/apiexport/controllers/apireconciler/apiexport_apireconciler_controller_test.go b/pkg/virtual/apiexport/controllers/apireconciler/apiexport_apireconciler_controller_test.go index 5fe580f2edf..01c945fbdc5 100644 --- a/pkg/virtual/apiexport/controllers/apireconciler/apiexport_apireconciler_controller_test.go +++ b/pkg/virtual/apiexport/controllers/apireconciler/apiexport_apireconciler_controller_test.go @@ -67,7 +67,7 @@ func TestEnqueueAPIResourceSchema(t *testing.T) { logger, _ := ktesting.NewTestContext(t) c.enqueueAPIResourceSchema(schema, logger) - require.Equal(t, c.queue.Len(), 2) + require.Equal(t, 2, c.queue.Len()) // get the queue keys actual := sets.New[string]() diff --git a/pkg/virtual/apiexport/schemas/builtin/builtin_test.go b/pkg/virtual/apiexport/schemas/builtin/builtin_test.go index 1d29f882afa..22cdb3528e2 100644 --- a/pkg/virtual/apiexport/schemas/builtin/builtin_test.go +++ b/pkg/virtual/apiexport/schemas/builtin/builtin_test.go @@ -49,5 +49,5 @@ func TestInit(t *testing.T) { require.Truef(t, versionFound, "could not find version %s in API resource schema %s", api.GroupVersion.String(), schema.Name) } - require.Equal(t, len(builtInAPIResourceSchemas), len(visitedResourceSchemas)) + require.Len(t, visitedResourceSchemas, len(builtInAPIResourceSchemas)) } diff --git a/test/e2e/apibinding/apibinding_deletion_test.go b/test/e2e/apibinding/apibinding_deletion_test.go index d7fa7c3c0f5..6d0785a6a9e 100644 --- a/test/e2e/apibinding/apibinding_deletion_test.go +++ b/test/e2e/apibinding/apibinding_deletion_test.go @@ -220,7 +220,7 @@ func TestAPIBindingDeletion(t *testing.T) { }, } _, err = cowboyClient.Create(t.Context(), cowboyDenied, metav1.CreateOptions{}) - require.Equal(t, apierrors.IsForbidden(err), true) + require.True(t, apierrors.IsForbidden(err)) t.Logf("Clean finalizer to remove the cowboy") err = retry.RetryOnConflict(retry.DefaultBackoff, func() error { diff --git a/test/e2e/apibinding/apibinding_test.go b/test/e2e/apibinding/apibinding_test.go index c88d3d7bbb7..b2e3ea76ab8 100644 --- a/test/e2e/apibinding/apibinding_test.go +++ b/test/e2e/apibinding/apibinding_test.go @@ -331,7 +331,7 @@ func TestAPIBinding(t *testing.T) { cowboyClient := wildwestClusterClient.Cluster(consumerWorkspace).WildwestV1alpha1().Cowboys("default") cowboys, err := cowboyClient.List(t.Context(), metav1.ListOptions{}) require.NoError(t, err, "error listing cowboys inside %q", consumerWorkspace) - require.Zero(t, len(cowboys.Items), "expected 0 cowboys inside %q", consumerWorkspace) + require.Empty(t, cowboys.Items, "expected 0 cowboys inside %q", consumerWorkspace) t.Logf("Create a cowboy CR in consumer workspace %q", consumerWorkspace) cowboyName := fmt.Sprintf("cowboy-%s", consumerWorkspace.Base()) @@ -347,7 +347,7 @@ func TestAPIBinding(t *testing.T) { t.Logf("Make sure there is 1 cowboy in consumer workspace %q", consumerWorkspace) cowboys, err = cowboyClient.List(t.Context(), metav1.ListOptions{}) require.NoError(t, err, "error listing cowboys in %q", consumerWorkspace) - require.Equal(t, 1, len(cowboys.Items), "expected 1 cowboy in %q", consumerWorkspace) + require.Len(t, cowboys.Items, 1, "expected 1 cowboy in %q", consumerWorkspace) require.Equal(t, cowboyName, cowboys.Items[0].Name, "unexpected name for cowboy in %q", consumerWorkspace) t.Logf("Create an APIBinding in consumer workspace %q that points to the today-cowboys export from serviceProvider2 (which should conflict)", consumerWorkspace) @@ -479,13 +479,13 @@ func TestAPIBinding(t *testing.T) { listErrs = append(listErrs, err) continue } - require.Equal(t, 1, len(list.Items), "unexpected # of cowboys through virtual workspace with explicit workspace") + require.Len(t, list.Items, 1, "unexpected # of cowboys through virtual workspace with explicit workspace") foundOnShards++ t.Logf("Listing %s|%s cowboys via virtual workspace wildcard list", provider2Path, exportName) list, err = vw2ClusterClient.Resource(gvr).List(t.Context(), metav1.ListOptions{}) require.NoError(t, err, "error listing through virtual workspace wildcard") - require.Equal(t, 1, len(list.Items), "unexpected # of cowboys through virtual workspace with wildcard") + require.Len(t, list.Items, 1, "unexpected # of cowboys through virtual workspace with wildcard") } if foundOnShards == 0 { diff --git a/test/e2e/apibinding/maximalpermissionpolicy_authorizer_test.go b/test/e2e/apibinding/maximalpermissionpolicy_authorizer_test.go index 51f829e61ce..b42666040f4 100644 --- a/test/e2e/apibinding/maximalpermissionpolicy_authorizer_test.go +++ b/test/e2e/apibinding/maximalpermissionpolicy_authorizer_test.go @@ -236,7 +236,7 @@ func TestMaximalPermissionPolicyAuthorizer(t *testing.T) { t.Logf("Make sure there is 1 cowboy in consumer workspace %q", consumer) cowboys, err := cowboyclient.List(t.Context(), metav1.ListOptions{}) require.NoError(t, err, "error listing cowboys in consumer workspace %q", consumer) - require.Equal(t, 1, len(cowboys.Items), "expected 1 cowboy in consumer workspace %q", consumer) + require.Len(t, cowboys.Items, 1, "expected 1 cowboy in consumer workspace %q", consumer) if serviceProvider == rbacServiceProviderPath { t.Logf("Make sure that the status of cowboy can not be updated in workspace %q", consumer) kcptestinghelpers.Eventually(t, func() (bool, string) { @@ -294,7 +294,7 @@ func TestMaximalPermissionPolicyAuthorizer(t *testing.T) { t.Logf("User 2 can list cowboys in consumer workspace %q before deleting APIExport", consumer) user2Cowboys, err := user2Client.Cluster(consumer).WildwestV1alpha1().Cowboys("default").List(t.Context(), metav1.ListOptions{}) require.NoError(t, err) - require.Equal(t, 3, len(user2Cowboys.Items), "expected 3 cowboys in consumer") + require.Len(t, user2Cowboys.Items, 3, "expected 3 cowboys in consumer") t.Logf("User 2 gets errors trying to delete an existing cowboy in consumer workspace %q", consumer) err = user2Client.Cluster(consumer).WildwestV1alpha1().Cowboys(cowboy2.ObjectMeta.Namespace).Delete(t.Context(), cowboy2.ObjectMeta.Name, metav1.DeleteOptions{}) @@ -328,7 +328,7 @@ func TestMaximalPermissionPolicyAuthorizer(t *testing.T) { t.Logf("Admin can list the cowboys in consumer workspace %q", consumer) cowboysAfterDelete, err := wildwestClusterClient.Cluster(consumer).WildwestV1alpha1().Cowboys("default").List(t.Context(), metav1.ListOptions{}) require.NoError(t, err, "error listing cowboys in consumer workspace %q", consumer) - require.Equal(t, 3, len(cowboysAfterDelete.Items), "expected 3 cowboy in consumer") + require.Len(t, cowboysAfterDelete.Items, 3, "expected 3 cowboy in consumer") t.Logf("Admin can delete an existing cowboy in consumer workspace %q", consumer) err = wildwestClusterClient.Cluster(consumer).WildwestV1alpha1().Cowboys(cowboy2.ObjectMeta.Namespace).Delete(t.Context(), cowboy2.ObjectMeta.Name, metav1.DeleteOptions{}) @@ -490,7 +490,7 @@ func testCRUDOperations(t *testing.T, consumer1Workspace logicalcluster.Path, wi cowboys, err = cowboyClient.List(t.Context(), metav1.ListOptions{}) return err == nil }, wait.ForeverTestTimeout, 100*time.Millisecond, "expected to be able to list ") - require.Zero(t, len(cowboys.Items), "expected 0 cowboys inside consumer workspace %q", consumer1Workspace) + require.Empty(t, cowboys.Items, "expected 0 cowboys inside consumer workspace %q", consumer1Workspace) t.Logf("Create a cowboy CR in consumer workspace %q", consumer1Workspace) cowboyName := fmt.Sprintf("cowboy-%s", consumer1Workspace.Base()) diff --git a/test/e2e/authorizer/serviceaccounts_test.go b/test/e2e/authorizer/serviceaccounts_test.go index c26adbe4a70..fc73c0ba770 100644 --- a/test/e2e/authorizer/serviceaccounts_test.go +++ b/test/e2e/authorizer/serviceaccounts_test.go @@ -204,7 +204,7 @@ func TestServiceAccounts(t *testing.T) { t.Log("Accessing workspace with the service account") obj, err := saKubeClusterClient.Cluster(otherPath).CoreV1().ConfigMaps(namespace.Name).List(ctx, metav1.ListOptions{}) - require.Error(t, err, fmt.Sprintf("expected error accessing workspace with the service account, got: %v", obj)) + require.Error(t, err, "expected error accessing workspace with the service account, got: %v", obj) t.Log("Giving the access to configmaps in the other workspace") _, err = kubeClusterClient.Cluster(otherPath).RbacV1().ClusterRoles().Create(ctx, &rbacv1.ClusterRole{ @@ -295,7 +295,7 @@ func TestServiceAccounts(t *testing.T) { t.Log("Accessing workspace with the service account") obj, err := saKubeClusterClient.Cluster(otherPath).CoreV1().ConfigMaps(namespace.Name).List(ctx, metav1.ListOptions{}) - require.Error(t, err, fmt.Sprintf("expected error accessing workspace with the service account, got: %v", obj)) + require.Error(t, err, "expected error accessing workspace with the service account, got: %v", obj) }) t.Run("A service account is allowed to escalate permissions implicitly", func(t *testing.T) { diff --git a/test/e2e/reconciler/apiexportendpointslice/apiexportendpointslice_test.go b/test/e2e/reconciler/apiexportendpointslice/apiexportendpointslice_test.go index f58f2b0f266..27ace3b6fd7 100644 --- a/test/e2e/reconciler/apiexportendpointslice/apiexportendpointslice_test.go +++ b/test/e2e/reconciler/apiexportendpointslice/apiexportendpointslice_test.go @@ -107,7 +107,7 @@ func TestAPIExportEndpointSliceWithPartition(t *testing.T) { require.True(t, apierrors.IsForbidden(err), "no error creating APIExportEndpointSlice (admission should have declined it)") sliceList, err := sliceClient.Cluster(partitionClusterPath).List(ctx, metav1.ListOptions{}) require.NoError(t, err, "error listing APIExportEndpointSlice") - require.True(t, len(sliceList.Items) == 0, "not expecting any APIExportEndpointSlice") + require.Empty(t, sliceList.Items, "not expecting any APIExportEndpointSlice") t.Logf("Creating the missing APIExport") exportClient := kcpClusterClient.ApisV1alpha2().APIExports() @@ -155,7 +155,7 @@ func TestAPIExportEndpointSliceWithPartition(t *testing.T) { return false, spew.Sdump(slice.Status.Conditions) }, wait.ForeverTestTimeout, 100*time.Millisecond, "expected missing Partition") - require.True(t, len(slice.Status.APIExportEndpoints) == 0, "not expecting any endpoint") + require.Empty(t, slice.Status.APIExportEndpoints, "not expecting any endpoint") t.Logf("Creating the missing Partition") partitionClient := kcpClusterClient.TopologyV1alpha1().Partitions() _, err = partitionClient.Cluster(partitionClusterPath).Create(ctx, partition, metav1.CreateOptions{}) @@ -172,7 +172,7 @@ func TestAPIExportEndpointSliceWithPartition(t *testing.T) { }, wait.ForeverTestTimeout, 100*time.Millisecond, "expected valid Partition") t.Logf("Checking that no endpoint has been populated") - require.True(t, len(slice.Status.APIExportEndpoints) == 0, "not expecting any endpoint") + require.Empty(t, slice.Status.APIExportEndpoints, "not expecting any endpoint") } func TestAPIBindingEndpointSlicesSharded(t *testing.T) { diff --git a/test/e2e/reconciler/cache/helpers.go b/test/e2e/reconciler/cache/helpers.go index 124c2d884dd..3d9029babbd 100644 --- a/test/e2e/reconciler/cache/helpers.go +++ b/test/e2e/reconciler/cache/helpers.go @@ -28,6 +28,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" utilerrors "k8s.io/apimachinery/pkg/util/errors" @@ -85,7 +86,7 @@ func StartStandaloneCacheServer(ctx context.Context, t *testing.T, dataDir strin start := time.Now() t.Logf("Starting the cache server") go func() { - require.NoError(t, preparedCachedServer.Run(ctx)) + assert.NoError(t, preparedCachedServer.Run(ctx)) }() cacheServerCertificatePath := path.Join(dataDir, "cache", "apiserver.crt") diff --git a/test/e2e/reconciler/partitionset/partitionset_test.go b/test/e2e/reconciler/partitionset/partitionset_test.go index 0d3730abfa3..6f7bc1bf7fa 100644 --- a/test/e2e/reconciler/partitionset/partitionset_test.go +++ b/test/e2e/reconciler/partitionset/partitionset_test.go @@ -89,7 +89,7 @@ func TestPartitionSet(t *testing.T) { }, wait.ForeverTestTimeout, 100*time.Millisecond, "expected valid partitionSet") partitions, err = partitionClient.Cluster(partitionClusterPath).List(ctx, metav1.ListOptions{}) require.NoError(t, err, "error retrieving partitions") - require.Equal(t, 0, len(partitions.Items), "no partition expected, got: %d", len(partitions.Items)) + require.Empty(t, partitions.Items, "no partition expected, got: %d", len(partitions.Items)) // Newly added shards are annotated to avoid side effects on other e2e tests. t.Logf("Creating a shard matching the partitionSet") @@ -395,6 +395,6 @@ func TestPartitionSetAdmission(t *testing.T) { }, wait.ForeverTestTimeout, 100*time.Millisecond, "expected 1 partition") expectedName := partitionSet.Name + "-" + strings.Join(labelValues, "-") expectedName = expectedName[:validation.DNS1123LabelMaxLength-5] - require.EqualValues(t, expectedName, partitions.Items[0].Name[:len(partitions.Items[0].Name)-5], + require.Equal(t, expectedName, partitions.Items[0].Name[:len(partitions.Items[0].Name)-5], "partition name not as expected, got: %s", partitions.Items[0].Name) } diff --git a/test/e2e/reconciler/workspacedeletion/controller_test.go b/test/e2e/reconciler/workspacedeletion/controller_test.go index 6e82f30ffc0..dc331154442 100644 --- a/test/e2e/reconciler/workspacedeletion/controller_test.go +++ b/test/e2e/reconciler/workspacedeletion/controller_test.go @@ -184,11 +184,11 @@ func TestWorkspaceDeletion(t *testing.T) { nslist, err := rootShardKubeClusterClient.Cluster(workspaceCluster).CoreV1().Namespaces().List(ctx, metav1.ListOptions{}) require.NoError(t, err, "failed to list namespaces in workspace %s", workspace.Name) - require.Equal(t, 0, len(nslist.Items)) + require.Empty(t, nslist.Items) cmlist, err := rootShardKubeClusterClient.Cluster(workspaceCluster).CoreV1().ConfigMaps(metav1.NamespaceAll).List(ctx, metav1.ListOptions{}) require.NoError(t, err, "failed to list configmaps in workspace %s", workspace.Name) - require.Equal(t, 0, len(cmlist.Items)) + require.Empty(t, cmlist.Items) }, }, { diff --git a/test/e2e/server/url_test.go b/test/e2e/server/url_test.go index 84d8762c8b2..c16e7ba7edd 100644 --- a/test/e2e/server/url_test.go +++ b/test/e2e/server/url_test.go @@ -95,7 +95,7 @@ func TestURLs(t *testing.T) { if !assert.Equal(t, testPath.expectedStatusCode, resp.StatusCode) { t.Logf("Expected status code %d, got %d", testPath.expectedStatusCode, resp.StatusCode) b, err := io.ReadAll(resp.Body) - assert.NoError(t, err) + assert.NoError(t, err) //nolint:testifylint // using assert here to still get the response body as far as possible t.Logf("Response body: %s", string(b)) } }) diff --git a/test/e2e/virtual/apiexport/binding_test.go b/test/e2e/virtual/apiexport/binding_test.go index 17fd26690a2..afaa3d2c3c5 100644 --- a/test/e2e/virtual/apiexport/binding_test.go +++ b/test/e2e/virtual/apiexport/binding_test.go @@ -347,7 +347,7 @@ func TestAPIBindingPermissionClaimsVerbs(t *testing.T) { t.Logf("Make sure secrets list shows nothing to start") secrets, err := kubeClusterClient.Cluster(consumerClusterName.Path()).CoreV1().Secrets("default").List(t.Context(), metav1.ListOptions{}) require.NoError(t, err, "error listing secrets inside %q", consumerPath) - require.Zero(t, len(secrets.Items), "expected 0 secrets inside %q", consumerPath) + require.Empty(t, secrets.Items, "expected 0 secrets inside %q", consumerPath) t.Logf("Create a secret in consumer workspace %q before allowing create", consumerPath) secretName := fmt.Sprintf("secret-%s", consumerPath.Base()) diff --git a/test/e2e/virtual/apiexport/virtualworkspace_test.go b/test/e2e/virtual/apiexport/virtualworkspace_test.go index 3168f31b3b7..b124dfabea2 100644 --- a/test/e2e/virtual/apiexport/virtualworkspace_test.go +++ b/test/e2e/virtual/apiexport/virtualworkspace_test.go @@ -119,7 +119,7 @@ func TestAPIExportVirtualWorkspace(t *testing.T) { require.NoError(t, err) cowboysProjected, err := wildwestVCClusterClient.WildwestV1alpha1().Cowboys().List(t.Context(), metav1.ListOptions{}) require.NoError(t, err) - require.Equal(t, 1, len(cowboysProjected.Items)) + require.Len(t, cowboysProjected.Items, 1) t.Logf("Verify that the virtual workspace includes apibindings") discoveryVCClusterClient, err := kcpdiscovery.NewForConfig(apiExportVWCfg) @@ -310,7 +310,7 @@ func TestAPIExportVirtualWorkspace(t *testing.T) { t.Logf("Verify that deleted cowboy is gone") cowboys, err := wwUser1VC.WildwestV1alpha1().Cowboys().List(t.Context(), metav1.ListOptions{}) require.NoError(t, err) - require.Equal(t, 2, len(cowboys.Items)) + require.Len(t, cowboys.Items, 2) names := make([]string, 0, len(cowboys.Items)) for _, c := range cowboys.Items { names = append(names, c.Name) @@ -324,7 +324,7 @@ func TestAPIExportVirtualWorkspace(t *testing.T) { t.Logf("Verify that all cowboys are gone") cowboys, err = wwUser1VC.WildwestV1alpha1().Cowboys().List(t.Context(), metav1.ListOptions{}) require.NoError(t, err) - require.Equal(t, 0, len(cowboys.Items)) + require.Empty(t, cowboys.Items) } } @@ -636,7 +636,7 @@ func TestAPIExportPermissionClaims(t *testing.T) { require.NoError(t, err) cowboys, err := wildwestVCClients.WildwestV1alpha1().Cowboys().List(t.Context(), metav1.ListOptions{}) require.NoError(t, err) - require.Equal(t, 1, len(cowboys.Items)) + require.Len(t, cowboys.Items, 1) t.Logf("Verify that we get empty lists for all claimed resources (other than apibindings) because the claims have not been accepted yet") dynamicVWClusterClient, err := kcpdynamic.NewForConfig(consumer1VWCfg) @@ -666,7 +666,7 @@ func TestAPIExportPermissionClaims(t *testing.T) { require.NoError(t, err, "error listing %q", gvr) if gvr == apisv1alpha2.SchemeGroupVersion.WithResource("apibindings") { // for this one we always see the reflexive objects - require.Equal(t, 1, len(list.Items), "expected to find 1 apibinding, got %#v", list.Items) + require.Len(t, list.Items, 1, "expected to find 1 apibinding, got %#v", list.Items) for _, binding := range list.Items { require.Equal(t, "cowboys", binding.GetName(), "expected binding name to be \"cowboys\"") } @@ -1107,7 +1107,7 @@ func createCowboyInConsumer(t *testing.T, consumer1Workspace logicalcluster.Path cowboys, err = cowboyClusterClient.List(t.Context(), metav1.ListOptions{}) return err == nil }, wait.ForeverTestTimeout, 100*time.Millisecond, "expected to be able to list ") - require.Zero(t, len(cowboys.Items), "expected 0 cowboys inside consumer workspace %q", consumer1Workspace) + require.Empty(t, cowboys.Items, "expected 0 cowboys inside consumer workspace %q", consumer1Workspace) t.Logf("Create a cowboy CR in consumer workspace %q", consumer1Workspace) cowboyName := fmt.Sprintf("cowboy-%s", consumer1Workspace.Base()) diff --git a/test/e2e/virtual/initializingworkspaces/virtualworkspace_test.go b/test/e2e/virtual/initializingworkspaces/virtualworkspace_test.go index baf54897217..4070f0ce8f7 100644 --- a/test/e2e/virtual/initializingworkspaces/virtualworkspace_test.go +++ b/test/e2e/virtual/initializingworkspaces/virtualworkspace_test.go @@ -453,7 +453,7 @@ func TestInitializingWorkspacesVirtualWorkspaceAccess(t *testing.T) { if logicalcluster.From(evt.Object.(metav1.Object)).String() != ws.Spec.Cluster { continue } - require.Equal(t, evt.Type, watch.Added) + require.Equal(t, watch.Added, evt.Type) case <-time.Tick(wait.ForeverTestTimeout): t.Fatalf("never saw a watche event for the %s initializer", initializer) } @@ -555,7 +555,7 @@ func TestInitializingWorkspacesVirtualWorkspaceAccess(t *testing.T) { if logicalcluster.From(evt.Object.(metav1.Object)).String() != ws.Spec.Cluster { continue } - require.Equal(t, evt.Type, watch.Deleted) + require.Equal(t, watch.Deleted, evt.Type) case <-time.Tick(wait.ForeverTestTimeout): t.Fatalf("never saw a watch event for the %s initializer", initializer) } diff --git a/test/e2e/virtual/terminatingworkspaces/virtualworkspace_test.go b/test/e2e/virtual/terminatingworkspaces/virtualworkspace_test.go index 90717f14ba4..05099dd9bd9 100644 --- a/test/e2e/virtual/terminatingworkspaces/virtualworkspace_test.go +++ b/test/e2e/virtual/terminatingworkspaces/virtualworkspace_test.go @@ -196,7 +196,7 @@ func TestTerminatingWorkspacesVirtualWorkspaceAccess(t *testing.T) { w, err = sourceKcpClusterClient.TenancyV1alpha1().Cluster(wsPath).Workspaces().Get(ctx, ws.Name, metav1.GetOptions{}) require.NoError(c, err) require.Contains(c, w.Annotations, "internal.tenancy.kcp.io/shard") - require.Equal(c, w.Status.Phase, corev1alpha1.LogicalClusterPhaseReady) + require.Equal(c, corev1alpha1.LogicalClusterPhaseReady, w.Status.Phase) require.NotEmpty(c, w.Status.Terminators) }, wait.ForeverTestTimeout, time.Millisecond*100) workspaces[name] = w @@ -401,7 +401,7 @@ func TestTerminatingWorkspacesVirtualWorkspaceAccess(t *testing.T) { }, wait.ForeverTestTimeout, 100*time.Millisecond) // check that the number of logical clusters matches - require.Equal(t, len(expLogicalClusters[name]), len(clusters)) + require.Len(t, clusters, len(expLogicalClusters[name])) for _, cluster := range clusters { // check that spec terminators are set correctly @@ -640,7 +640,7 @@ func TestTerminatingWorkspacesVirtualWorkspaceWatch(t *testing.T) { ws, err = sourceKcpClusterClient.TenancyV1alpha1().Cluster(wsPath).Workspaces().Get(ctx, ws.Name, metav1.GetOptions{}) require.NoError(c, err) require.Contains(c, ws.Annotations, "internal.tenancy.kcp.io/shard") - require.Equal(c, ws.Status.Phase, corev1alpha1.LogicalClusterPhaseReady) + require.Equal(c, corev1alpha1.LogicalClusterPhaseReady, ws.Status.Phase) require.NotEmpty(c, ws.Status.Terminators) }, wait.ForeverTestTimeout, 100*time.Millisecond) require.EventuallyWithT(t, func(c *assert.CollectT) { diff --git a/test/e2e/virtualresources/cachedresources/vr_cachedresources_test.go b/test/e2e/virtualresources/cachedresources/vr_cachedresources_test.go index 4e1e2490b79..cc0f83eb8e5 100644 --- a/test/e2e/virtualresources/cachedresources/vr_cachedresources_test.go +++ b/test/e2e/virtualresources/cachedresources/vr_cachedresources_test.go @@ -435,17 +435,15 @@ func TestCachedResources(t *testing.T) { Resource(wildwestv1alpha1.SchemeGroupVersion.WithResource(resourceName)). List(ctx, metav1.ListOptions{}) require.NoError(t, err) - require.Equal(t, 1, len(list.Items), "Unexpected number of items in %s list in %q when listing through %q", resourceName, consumerPath, host) - - require.NoError(t, err) - require.EqualValues(t, wildwestObjsNormalizedUnstructured[objName], normalizeUnstructuredMap(list.Items[0].Object)) + require.Len(t, list.Items, 1, "Unexpected number of items in %s list in %q when listing through %q", resourceName, consumerPath, host) + require.Equal(t, wildwestObjsNormalizedUnstructured[objName], normalizeUnstructuredMap(list.Items[0].Object)) t.Logf("Getting a %s resource named %s in %q via %q should return that object", resourceName, objName, consumerPath, host) obj, err := dynClient.Cluster(logicalcluster.NewPath(consumerWS.Spec.Cluster)). Resource(wildwestv1alpha1.SchemeGroupVersion.WithResource(resourceName)). Get(ctx, objName, metav1.GetOptions{}) require.NoError(t, err) - require.EqualValues(t, wildwestObjsNormalizedUnstructured[objName], normalizeUnstructuredMap(obj.Object)) + require.Equal(t, wildwestObjsNormalizedUnstructured[objName], normalizeUnstructuredMap(obj.Object)) } } } diff --git a/test/e2e/watchcache/watchcache_enabled_test.go b/test/e2e/watchcache/watchcache_enabled_test.go index 6c9c4466fe9..2dd58e544da 100644 --- a/test/e2e/watchcache/watchcache_enabled_test.go +++ b/test/e2e/watchcache/watchcache_enabled_test.go @@ -97,7 +97,7 @@ func TestWatchCacheEnabledForCRD(t *testing.T) { for range 10 { res, err := wildwestClusterClient.Cluster(wsPath).WildwestV1alpha1().Cowboys("default").List(t.Context(), metav1.ListOptions{ResourceVersion: "0"}) require.NoError(t, err) - require.Equal(t, 1, len(res.Items), "expected to get exactly one cowboy") + require.Len(t, res.Items, 1, "expected to get exactly one cowboy") } totalCacheHits, cowboysCacheHit := collectCacheHitsFor(t.Context(), t, server.RootShardSystemMasterBaseConfig(t), "wildwest.dev", "cowboys") @@ -147,7 +147,7 @@ func TestWatchCacheEnabledForAPIBindings(t *testing.T) { for range 10 { res, err := dynamicKcpClusterClient.Cluster(wsConsume1aPath).Resource(sheriffsGVR).Namespace("default").List(t.Context(), metav1.ListOptions{ResourceVersion: "0"}) require.NoError(t, err) - require.Equal(t, 1, len(res.Items), "expected to get exactly one sheriff") + require.Len(t, res.Items, 1, "expected to get exactly one sheriff") } totalCacheHits, sheriffsCacheHit := collectCacheHitsFor(t.Context(), t, server.RootShardSystemMasterBaseConfig(t), "newyork.io", "sheriffs") diff --git a/test/e2e/workspace/deletion_test.go b/test/e2e/workspace/deletion_test.go index db1e1cc2a83..62fab1d1e2c 100644 --- a/test/e2e/workspace/deletion_test.go +++ b/test/e2e/workspace/deletion_test.go @@ -85,7 +85,7 @@ func TestWorkspaceLogicalClusterRelationship(t *testing.T) { require.EventuallyWithT(t, func(c *assert.CollectT) { lc, err := clientset.Cluster(testPath).CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, v1.GetOptions{}) require.NoError(c, err, "error getting logicalcluster") - require.NotEqual(c, nil, lc.DeletionTimestamp) + require.NotNil(c, lc.DeletionTimestamp) require.Contains(c, lc.Finalizers, customFinalizer) require.NotContains(c, lc.Finalizers, logicalclusterdeletion.LogicalClusterDeletionFinalizer) }, wait.ForeverTestTimeout, 100*time.Millisecond, "waiting for logicalcluster to be marked for deletion") @@ -95,7 +95,7 @@ func TestWorkspaceLogicalClusterRelationship(t *testing.T) { require.EventuallyWithT(t, func(c *assert.CollectT) { ws, err := clientset.Cluster(fixtureRoot).TenancyV1alpha1().Workspaces().Get(ctx, wsName, v1.GetOptions{}) require.NoError(c, err, "error getting workspace") - require.NotEqual(c, nil, ws.DeletionTimestamp) + require.NotNil(c, ws.DeletionTimestamp) require.Contains(c, ws.Finalizers, corev1alpha1.LogicalClusterFinalizerName) }, wait.ForeverTestTimeout, 100*time.Millisecond, "waiting for workspace to be marked for deletion") diff --git a/test/e2e/workspace/inactive_test.go b/test/e2e/workspace/inactive_test.go index 944dff44c95..443d1b70582 100644 --- a/test/e2e/workspace/inactive_test.go +++ b/test/e2e/workspace/inactive_test.go @@ -20,7 +20,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -73,7 +72,6 @@ func TestInactiveLogicalCluster(t *testing.T) { require.NoError(t, err) t.Log("Verify that normal requests succeed again") - assert.NoError(t, err, "expected no error when accessing an active logical cluster") kcptestinghelpers.Eventually(t, func() (bool, string) { _, err := kubeClient.Cluster(orgPath).CoreV1().Namespaces().List(t.Context(), v1.ListOptions{}) if err != nil { diff --git a/test/e2e/workspacetype/controller_test.go b/test/e2e/workspacetype/controller_test.go index c69465bb13f..38929961afa 100644 --- a/test/e2e/workspacetype/controller_test.go +++ b/test/e2e/workspacetype/controller_test.go @@ -82,10 +82,10 @@ func TestWorkspaceTypes(t *testing.T) { t.Logf("Expect workspace to be of universal type, and no initializers") workspace, err = server.kcpClusterClient.TenancyV1alpha1().Workspaces().Cluster(server.orgPath).Get(ctx, workspace.Name, metav1.GetOptions{}) require.NoError(t, err, "failed to get workspace") - require.Equalf(t, workspace.Spec.Type, &tenancyv1alpha1.WorkspaceTypeReference{ + require.Equalf(t, &tenancyv1alpha1.WorkspaceTypeReference{ Name: "universal", Path: "root", - }, "workspace type is not universal") + }, workspace.Spec.Type, "workspace type is not universal") require.Emptyf(t, workspace.Status.Initializers, "workspace has initializers") }, }, @@ -139,10 +139,10 @@ func TestWorkspaceTypes(t *testing.T) { server.RunningServer.Artifact(t, func() (runtime.Object, error) { return server.kcpClusterClient.TenancyV1alpha1().Workspaces().Cluster(universalPath).Get(ctx, "myapp", metav1.GetOptions{}) }) - require.Equal(t, workspace.Spec.Type, &tenancyv1alpha1.WorkspaceTypeReference{ + require.Equal(t, &tenancyv1alpha1.WorkspaceTypeReference{ Name: "foo", Path: logicalcluster.From(wt).String(), - }) + }, workspace.Spec.Type) t.Logf("Expect workspace to become ready because there are no initializers") require.Eventually(t, func() bool { @@ -233,11 +233,10 @@ func TestWorkspaceTypes(t *testing.T) { server.RunningServer.Artifact(t, func() (runtime.Object, error) { return server.kcpClusterClient.Cluster(universalPath).TenancyV1alpha1().Workspaces().Get(ctx, "myapp", metav1.GetOptions{}) }) - require.Equal(t, workspace.Spec.Type, - &tenancyv1alpha1.WorkspaceTypeReference{ - Name: "bar", - Path: logicalcluster.From(wt).String(), - }) + require.Equal(t, &tenancyv1alpha1.WorkspaceTypeReference{ + Name: "bar", + Path: logicalcluster.From(wt).String(), + }, workspace.Spec.Type) t.Logf("Expect workspace %q of type \"foo\" to become ready because there are no initializers", workspace.Name) require.Eventually(t, func() bool { diff --git a/test/integration/framework/server_test.go b/test/integration/framework/server_test.go index 9abc3a120b1..8804ba16ed3 100644 --- a/test/integration/framework/server_test.go +++ b/test/integration/framework/server_test.go @@ -54,13 +54,13 @@ func TestServerCreateConfigMap(t *testing.T) { ConfigMaps(metav1.NamespaceDefault) _, err := cmi.Create(context.Background(), configmap, metav1.CreateOptions{}) - require.Nil(t, err) + require.NoError(t, err) cm, err := cmi.Get(context.Background(), configmap.ObjectMeta.Name, metav1.GetOptions{}) - require.Nil(t, err) + require.NoError(t, err) require.NotNil(t, cm) require.Equal(t, configmap.Data, cm.Data) err = cmi.Delete(context.Background(), configmap.ObjectMeta.Name, metav1.DeleteOptions{}) - require.Nil(t, err) + require.NoError(t, err) } From 3abb6282194ddb063208cd6462c23ba7c419fb35 Mon Sep 17 00:00:00 2001 From: "Nelo-T. Wallus" Date: Fri, 20 Mar 2026 08:04:50 +0100 Subject: [PATCH 2/2] Enable testifylint linter Signed-off-by: Nelo-T. Wallus Signed-off-by: Nelo-T. Wallus --- .golangci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yaml b/.golangci.yaml index d9be8c84573..f5ff9bcce5c 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -35,6 +35,7 @@ linters: - unused - usestdlibvars - whitespace + - testifylint # TODO(vincepri): Figure out if we want to enable or remove the following linters: # - predeclared # - goconst