Skip to content

Commit 329753c

Browse files
authored
Merge pull request #8087 from oscr/ginkgolinter-len-assertion
🌱 Enable ginkgolinter len assertion check and fix findings
2 parents 9ae5fc5 + 7ab078e commit 329753c

File tree

29 files changed

+65
-65
lines changed

29 files changed

+65
-65
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ linters-settings:
6262
local-prefixes: "sigs.k8s.io/cluster-api"
6363
ginkgolinter:
6464
# Suppress the wrong length assertion warning.
65-
suppress-len-assertion: true
65+
suppress-len-assertion: false
6666
# Suppress the wrong nil assertion warning.
6767
suppress-nil-assertion: false
6868
# Suppress the wrong error assertion warning.

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ func TestKubeadmConfigReconciler_Reconcile_GenerateCloudConfigData(t *testing.T)
524524

525525
// Expect the Secret to exist, and for it to contain some data under the "value" key.
526526
g.Expect(myclient.Get(ctx, client.ObjectKey{Namespace: metav1.NamespaceDefault, Name: configName}, s)).To(Succeed())
527-
g.Expect(len(s.Data["value"])).To(BeNumerically(">", 0))
527+
g.Expect(s.Data["value"]).ToNot(BeEmpty())
528528
// Ensure that we don't fail trying to refresh any bootstrap tokens
529529
_, err = k.Reconcile(ctx, request)
530530
g.Expect(err).NotTo(HaveOccurred())
@@ -703,7 +703,7 @@ func TestReconcileIfJoinCertificatesAvailableConditioninNodesAndControlPlaneIsRe
703703
l := &corev1.SecretList{}
704704
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
705705
g.Expect(err).NotTo(HaveOccurred())
706-
g.Expect(len(l.Items)).To(Equal(1))
706+
g.Expect(l.Items).To(HaveLen(1))
707707
})
708708
}
709709
}
@@ -779,7 +779,7 @@ func TestReconcileIfJoinNodePoolsAndControlPlaneIsReady(t *testing.T) {
779779
l := &corev1.SecretList{}
780780
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
781781
g.Expect(err).NotTo(HaveOccurred())
782-
g.Expect(len(l.Items)).To(Equal(1))
782+
g.Expect(l.Items).To(HaveLen(1))
783783
})
784784
}
785785
}
@@ -1053,7 +1053,7 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {
10531053
l := &corev1.SecretList{}
10541054
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
10551055
g.Expect(err).NotTo(HaveOccurred())
1056-
g.Expect(len(l.Items)).To(Equal(2))
1056+
g.Expect(l.Items).To(HaveLen(2))
10571057

10581058
// ensure that the token is refreshed...
10591059
tokenExpires := make([][]byte, len(l.Items))
@@ -1086,7 +1086,7 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {
10861086
l = &corev1.SecretList{}
10871087
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
10881088
g.Expect(err).NotTo(HaveOccurred())
1089-
g.Expect(len(l.Items)).To(Equal(2))
1089+
g.Expect(l.Items).To(HaveLen(2))
10901090

10911091
for i, item := range l.Items {
10921092
g.Expect(bytes.Equal(tokenExpires[i], item.Data[bootstrapapi.BootstrapTokenExpirationKey])).To(BeFalse())
@@ -1128,7 +1128,7 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {
11281128
l = &corev1.SecretList{}
11291129
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
11301130
g.Expect(err).NotTo(HaveOccurred())
1131-
g.Expect(len(l.Items)).To(Equal(2))
1131+
g.Expect(l.Items).To(HaveLen(2))
11321132

11331133
for i, item := range l.Items {
11341134
g.Expect(bytes.Equal(tokenExpires[i], item.Data[bootstrapapi.BootstrapTokenExpirationKey])).To(BeFalse())
@@ -1179,7 +1179,7 @@ func TestBootstrapTokenTTLExtension(t *testing.T) {
11791179
l = &corev1.SecretList{}
11801180
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
11811181
g.Expect(err).NotTo(HaveOccurred())
1182-
g.Expect(len(l.Items)).To(Equal(2))
1182+
g.Expect(l.Items).To(HaveLen(2))
11831183

11841184
for i, item := range l.Items {
11851185
g.Expect(bytes.Equal(tokenExpires[i], item.Data[bootstrapapi.BootstrapTokenExpirationKey])).To(BeTrue())
@@ -1237,7 +1237,7 @@ func TestBootstrapTokenRotationMachinePool(t *testing.T) {
12371237
l := &corev1.SecretList{}
12381238
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
12391239
g.Expect(err).NotTo(HaveOccurred())
1240-
g.Expect(len(l.Items)).To(Equal(1))
1240+
g.Expect(l.Items).To(HaveLen(1))
12411241

12421242
// ensure that the token is refreshed...
12431243
tokenExpires := make([][]byte, len(l.Items))
@@ -1264,7 +1264,7 @@ func TestBootstrapTokenRotationMachinePool(t *testing.T) {
12641264
l = &corev1.SecretList{}
12651265
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
12661266
g.Expect(err).NotTo(HaveOccurred())
1267-
g.Expect(len(l.Items)).To(Equal(1))
1267+
g.Expect(l.Items).To(HaveLen(1))
12681268

12691269
for i, item := range l.Items {
12701270
g.Expect(bytes.Equal(tokenExpires[i], item.Data[bootstrapapi.BootstrapTokenExpirationKey])).To(BeFalse())
@@ -1292,7 +1292,7 @@ func TestBootstrapTokenRotationMachinePool(t *testing.T) {
12921292
l = &corev1.SecretList{}
12931293
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
12941294
g.Expect(err).NotTo(HaveOccurred())
1295-
g.Expect(len(l.Items)).To(Equal(1))
1295+
g.Expect(l.Items).To(HaveLen(1))
12961296

12971297
for i, item := range l.Items {
12981298
g.Expect(bytes.Equal(tokenExpires[i], item.Data[bootstrapapi.BootstrapTokenExpirationKey])).To(BeFalse())
@@ -1324,7 +1324,7 @@ func TestBootstrapTokenRotationMachinePool(t *testing.T) {
13241324
l = &corev1.SecretList{}
13251325
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
13261326
g.Expect(err).NotTo(HaveOccurred())
1327-
g.Expect(len(l.Items)).To(Equal(1))
1327+
g.Expect(l.Items).To(HaveLen(1))
13281328

13291329
for i, item := range l.Items {
13301330
g.Expect(bytes.Equal(tokenExpires[i], item.Data[bootstrapapi.BootstrapTokenExpirationKey])).To(BeTrue())
@@ -1349,7 +1349,7 @@ func TestBootstrapTokenRotationMachinePool(t *testing.T) {
13491349
l = &corev1.SecretList{}
13501350
err = myclient.List(ctx, l, client.ListOption(client.InNamespace(metav1.NamespaceSystem)))
13511351
g.Expect(err).NotTo(HaveOccurred())
1352-
g.Expect(len(l.Items)).To(Equal(2))
1352+
g.Expect(l.Items).To(HaveLen(2))
13531353
foundOld := false
13541354
foundNew := true
13551355
for _, item := range l.Items {

cmd/clusterctl/client/cluster/components_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,15 @@ func Test_providerComponents_DeleteCoreProviderWebhookNamespace(t *testing.T) {
326326

327327
// assert length before deleting
328328
_ = proxyClient.List(ctx, &nsList)
329-
g.Expect(len(nsList.Items)).Should(Equal(1))
329+
g.Expect(nsList.Items).Should(HaveLen(1))
330330

331331
c := newComponentsClient(proxy)
332332
err := c.DeleteWebhookNamespace()
333333
g.Expect(err).To(Not(HaveOccurred()))
334334

335335
// assert length after deleting
336336
_ = proxyClient.List(ctx, &nsList)
337-
g.Expect(len(nsList.Items)).Should(Equal(0))
337+
g.Expect(nsList.Items).Should(BeEmpty())
338338
})
339339
}
340340

cmd/clusterctl/client/cluster/objectgraph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ func assertGraph(t *testing.T, got *objectGraph, want wantGraph) {
252252

253253
g := NewWithT(t)
254254

255-
g.Expect(len(got.uidToNode)).To(Equal(len(want.nodes)), "the number of nodes in the objectGraph doesn't match the number of expected nodes")
255+
g.Expect(got.uidToNode).To(HaveLen(len(want.nodes)), "the number of nodes in the objectGraph doesn't match the number of expected nodes")
256256

257257
for uid, wantNode := range want.nodes {
258258
gotNode, ok := got.uidToNode[types.UID(uid)]

cmd/clusterctl/client/cluster/topology_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,13 @@ func Test_topologyClient_Plan(t *testing.T) {
284284
g.Expect(err).NotTo(HaveOccurred())
285285

286286
// Check affected ClusterClasses.
287-
g.Expect(len(res.ClusterClasses)).To(Equal(len(tt.want.affectedClusterClasses)))
287+
g.Expect(res.ClusterClasses).To(HaveLen(len(tt.want.affectedClusterClasses)))
288288
for _, cc := range tt.want.affectedClusterClasses {
289289
g.Expect(res.ClusterClasses).To(ContainElement(cc))
290290
}
291291

292292
// Check affected Clusters.
293-
g.Expect(len(res.Clusters)).To(Equal(len(tt.want.affectedClusters)))
293+
g.Expect(res.Clusters).To(HaveLen(len(tt.want.affectedClusters)))
294294
for _, cluster := range tt.want.affectedClusters {
295295
g.Expect(res.Clusters).To(ContainElement(cluster))
296296
}

cmd/clusterctl/client/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func Test_getComponentsByName_withEmptyVariables(t *testing.T) {
262262
}
263263
components, err := client.GetProviderComponents(repository1Config.Name(), repository1Config.Type(), options)
264264
g.Expect(err).NotTo(HaveOccurred())
265-
g.Expect(len(components.Variables())).To(Equal(1))
265+
g.Expect(components.Variables()).To(HaveLen(1))
266266
g.Expect(components.Name()).To(Equal("p1"))
267267
}
268268

cmd/clusterctl/client/repository/template_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ metadata:
154154

155155
merged, err := MergeTemplates(template1, template2)
156156
g.Expect(err).NotTo(HaveOccurred())
157-
g.Expect(len(merged.Objs())).To(Equal(2))
158-
g.Expect(len(merged.VariableMap())).To(Equal(3))
157+
g.Expect(merged.Objs()).To(HaveLen(2))
158+
g.Expect(merged.VariableMap()).To(HaveLen(3))
159159

160160
// Make sure that the SAME_VARIABLE default value comes from the first template
161161
// that defines it

cmd/clusterctl/internal/util/obj_refs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestGetObjectReferences(t *testing.T) {
8686
return
8787
}
8888
g.Expect(err).NotTo(HaveOccurred())
89-
g.Expect(len(got)).To(Equal(len(tt.want)))
89+
g.Expect(got).To(HaveLen(len(tt.want)))
9090
for i := range got {
9191
g.Expect(got[i].Kind).To(Equal(tt.want[i].Kind))
9292
g.Expect(got[i].Name).To(Equal(tt.want[i].Name))

controllers/remote/keyedmutex_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestKeyedMutex(t *testing.T) {
4444
km.Unlock(cluster1)
4545

4646
// Ensure that the lock was cleaned up from the internal map.
47-
g.Expect(km.locks).To(HaveLen(0))
47+
g.Expect(km.locks).To(BeEmpty())
4848
})
4949

5050
t.Run("Can lock different Clusters in parallel but each one only once", func(t *testing.T) {
@@ -77,6 +77,6 @@ func TestKeyedMutex(t *testing.T) {
7777
}
7878

7979
// Ensure that the lock was cleaned up from the internal map.
80-
g.Expect(km.locks).To(HaveLen(0))
80+
g.Expect(km.locks).To(BeEmpty())
8181
})
8282
}

controlplane/kubeadm/api/v1beta1/kubeadm_control_plane_webhook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,9 +1167,9 @@ func TestValidateVersion(t *testing.T) {
11671167

11681168
allErrs := kcp.validateVersion(tt.oldVersion)
11691169
if tt.expectErr {
1170-
g.Expect(allErrs).ToNot(HaveLen(0))
1170+
g.Expect(allErrs).ToNot(BeEmpty())
11711171
} else {
1172-
g.Expect(allErrs).To(HaveLen(0))
1172+
g.Expect(allErrs).To(BeEmpty())
11731173
}
11741174
})
11751175
}

0 commit comments

Comments
 (0)