Skip to content

Commit 932f65f

Browse files
committed
Enable ginkgolinter and fix findings
Signed-off-by: Nahshon Unna-Tsameret <[email protected]>
1 parent ea5331d commit 932f65f

17 files changed

+60
-57
lines changed

.golangci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ linters:
2121
- errchkjson
2222
- exportloopref
2323
- gci
24-
# - ginkgolinter
24+
- ginkgolinter
2525
- goconst
2626
- gocritic
2727
- godot
@@ -172,6 +172,9 @@ linters-settings:
172172
- name: bool-literal-in-expr
173173
- name: constant-logical-expr
174174

175+
ginkgolinter:
176+
forbid-focus-container: true
177+
175178
issues:
176179
max-same-issues: 0
177180
max-issues-per-linter: 0

controllers/clustermodule_reconciler_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func TestReconciler_Reconcile(t *testing.T) {
288288
// if cluster module creation fails due to resource pool owner incompatibility, vSphereCluster object is set to Ready
289289
haveError: false,
290290
customAssert: func(g *gomega.WithT, ctx *context.ClusterContext) {
291-
g.Expect(ctx.VSphereCluster.Spec.ClusterModules).To(gomega.HaveLen(0))
291+
g.Expect(ctx.VSphereCluster.Spec.ClusterModules).To(gomega.BeEmpty())
292292
g.Expect(conditions.Has(ctx.VSphereCluster, infrav1.ClusterModulesAvailableCondition)).To(gomega.BeTrue())
293293
g.Expect(conditions.IsFalse(ctx.VSphereCluster, infrav1.ClusterModulesAvailableCondition)).To(gomega.BeTrue())
294294
g.Expect(conditions.Get(ctx.VSphereCluster, infrav1.ClusterModulesAvailableCondition).Message).To(gomega.ContainSubstring("kcp"))
@@ -387,7 +387,7 @@ func TestReconciler_Reconcile(t *testing.T) {
387387
svc.On("Remove", mock.Anything, mdUUID).Return(nil)
388388
},
389389
customAssert: func(g *gomega.WithT, ctx *context.ClusterContext) {
390-
g.Expect(ctx.VSphereCluster.Spec.ClusterModules).To(gomega.HaveLen(0))
390+
g.Expect(ctx.VSphereCluster.Spec.ClusterModules).To(gomega.BeEmpty())
391391
},
392392
},
393393
{
@@ -399,7 +399,7 @@ func TestReconciler_Reconcile(t *testing.T) {
399399
},
400400
clusterModules: []infrav1.ClusterModule{},
401401
customAssert: func(g *gomega.WithT, ctx *context.ClusterContext) {
402-
g.Expect(ctx.VSphereCluster.Spec.ClusterModules).To(gomega.HaveLen(0))
402+
g.Expect(ctx.VSphereCluster.Spec.ClusterModules).To(gomega.BeEmpty())
403403
},
404404
},
405405
}

controllers/serviceaccount_controller_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func assertRoleWithGetPVC(ctx *helpers.UnitTestContextForController, ctrlClient
129129
}
130130
err := ctrlClient.List(ctx, &roleList, opts)
131131
Expect(err).ShouldNot(HaveOccurred())
132-
Expect(len(roleList.Items)).To(Equal(1))
132+
Expect(roleList.Items).To(HaveLen(1))
133133
Expect(roleList.Items[0].Name).To(Equal(name))
134134
Expect(roleList.Items[0].Rules).To(Equal([]rbacv1.PolicyRule{
135135
{
@@ -147,7 +147,7 @@ func assertRoleBinding(_ *helpers.UnitTestContextForController, ctrlClient clien
147147
}
148148
err := ctrlClient.List(goctx.TODO(), &roleBindingList, opts)
149149
Expect(err).ShouldNot(HaveOccurred())
150-
Expect(len(roleBindingList.Items)).To(Equal(1))
150+
Expect(roleBindingList.Items).To(HaveLen(1))
151151
Expect(roleBindingList.Items[0].Name).To(Equal(name))
152152
Expect(roleBindingList.Items[0].RoleRef).To(Equal(rbacv1.RoleRef{
153153
Name: name,

controllers/vmware/vspherecluster_reconciler_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ var _ = Describe("Cluster Controller Tests", func() {
127127

128128
It("should not find FailureDomains", func() {
129129
fds, err := reconciler.getFailureDomains(ctx)
130-
Expect(err).To(BeNil())
131-
Expect(fds).Should(HaveLen(0))
130+
Expect(err).ToNot(HaveOccurred())
131+
Expect(fds).Should(BeEmpty())
132132
})
133133

134134
It("should find FailureDomains", func() {
@@ -148,7 +148,7 @@ var _ = Describe("Cluster Controller Tests", func() {
148148
}
149149

150150
fds, err := reconciler.getFailureDomains(ctx)
151-
Expect(err).To(BeNil())
151+
Expect(err).ToNot(HaveOccurred())
152152
Expect(fds).NotTo(BeNil())
153153
Expect(fds).Should(HaveLen(3))
154154
})

controllers/vspheredeploymentzone_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ func TestVSphereDeploymentZoneReconciler_ReconcileDelete(t *testing.T) {
648648
reconciler := vsphereDeploymentZoneReconciler{controllerCtx}
649649
err := reconciler.reconcileDelete(deploymentZoneCtx)
650650
g.Expect(err).NotTo(HaveOccurred())
651-
g.Expect(vsphereDeploymentZone.Finalizers).To(HaveLen(0))
651+
g.Expect(vsphereDeploymentZone.Finalizers).To(BeEmpty())
652652
})
653653
})
654654

@@ -667,7 +667,7 @@ func TestVSphereDeploymentZoneReconciler_ReconcileDelete(t *testing.T) {
667667
reconciler := vsphereDeploymentZoneReconciler{controllerCtx}
668668
err := reconciler.reconcileDelete(deploymentZoneCtx)
669669
g.Expect(err).NotTo(HaveOccurred())
670-
g.Expect(vsphereDeploymentZone.Finalizers).To(HaveLen(0))
670+
g.Expect(vsphereDeploymentZone.Finalizers).To(BeEmpty())
671671
})
672672

673673
t.Run("when no machines are present", func(t *testing.T) {
@@ -684,7 +684,7 @@ func TestVSphereDeploymentZoneReconciler_ReconcileDelete(t *testing.T) {
684684
reconciler := vsphereDeploymentZoneReconciler{controllerCtx}
685685
err := reconciler.reconcileDelete(deploymentZoneCtx)
686686
g.Expect(err).NotTo(HaveOccurred())
687-
g.Expect(vsphereDeploymentZone.Finalizers).To(HaveLen(0))
687+
g.Expect(vsphereDeploymentZone.Finalizers).To(BeEmpty())
688688
})
689689

690690
t.Run("delete failure domain", func(t *testing.T) {

pkg/manager/manager_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ password: '%s'
5757

5858
watch, err := InitializeWatch(fake.NewControllerManagerContext(), managerOptsTest)
5959
// Match initial credentials
60-
g.Expect(err).To(BeNil())
60+
g.Expect(err).ToNot(HaveOccurred())
6161
g.Expect(managerOptsTest.Username).To(Equal(username))
6262
g.Expect(managerOptsTest.Password).To(Equal(password))
6363

6464
// Update the file and wait for watch to detect the change
6565
content := fmt.Sprintf(contentFmt, updatedUsername, updatedPassword)
6666
_, err = tmpFile.Write([]byte(content))
67-
g.Expect(err).To(BeNil())
67+
g.Expect(err).ToNot(HaveOccurred())
6868

6969
g.Eventually(func() bool {
7070
return managerOptsTest.Username == updatedUsername && managerOptsTest.Password == updatedPassword
@@ -89,7 +89,7 @@ password: '%s'
8989
}
9090
watch, err := InitializeWatch(fake.NewControllerManagerContext(), managerOptsTest)
9191
// Match initial credentials
92-
g.Expect(err).To(BeNil())
92+
g.Expect(err).ToNot(HaveOccurred())
9393
g.Expect(managerOptsTest.Username).To(Equal(username))
9494
g.Expect(managerOptsTest.Password).To(Equal(password))
9595

@@ -124,6 +124,6 @@ password: '%s'
124124
}
125125
_, err = InitializeWatch(fake.NewControllerManagerContext(), managerOptsTest)
126126
// Match initial credentials
127-
g.Expect(err).NotTo(BeNil())
127+
g.Expect(err).To(HaveOccurred())
128128
})
129129
}

pkg/record/recorder_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ var _ = Describe("Event utils", func() {
3535
It("should not publish an event", func() {
3636
var err error
3737
recorder.EmitEvent(nil, "Create", err, true)
38-
Expect(len(fakeRecorder.Events)).Should(Equal(0))
38+
Expect(fakeRecorder.Events).Should(BeEmpty())
3939
})
4040

4141
It("should publish a success event", func() {
4242
var err error
4343
recorder.EmitEvent(nil, "Create", err, false)
44-
Expect(len(fakeRecorder.Events)).Should(Equal(1))
44+
Expect(fakeRecorder.Events).Should(HaveLen(1))
4545
event := <-fakeRecorder.Events
4646
Expect(event).Should(Equal("Normal CreateSuccess Create success"))
4747
})
4848

4949
It("should publish a failure event", func() {
5050
err := errors.New("something wrong")
5151
recorder.EmitEvent(nil, "Create", err, false)
52-
Expect(len(fakeRecorder.Events)).Should(Equal(1))
52+
Expect(fakeRecorder.Events).Should(HaveLen(1))
5353
event := <-fakeRecorder.Events
5454
Expect(event).Should(Equal("Warning CreateFailure something wrong"))
5555
})
@@ -60,13 +60,13 @@ var _ = Describe("Event utils", func() {
6060

6161
recorder.Eventf(nil, "Create", message, fmtArgs...)
6262
recorder.Warnf(nil, "Create", message, fmtArgs...)
63-
Expect(len(fakeRecorder.Events)).To(Equal(2))
63+
Expect(fakeRecorder.Events).To(HaveLen(2))
6464
eventFmt := <-fakeRecorder.Events
6565
warnFmt := <-fakeRecorder.Events
6666

6767
recorder.Event(nil, "Create", message)
6868
recorder.Warn(nil, "Create", message)
69-
Expect(len(fakeRecorder.Events)).To(Equal(2))
69+
Expect(fakeRecorder.Events).To(HaveLen(2))
7070
eventNoFmt := <-fakeRecorder.Events
7171
warnNoFmt := <-fakeRecorder.Events
7272

pkg/services/govmomi/cluster/service_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ func TestListHostsFromGroup(t *testing.T) {
5757

5858
refs, err = ListHostsFromGroup(context.Background(), ccr, "blah")
5959
g.Expect(err).NotTo(HaveOccurred())
60-
g.Expect(refs).To(HaveLen(0))
60+
g.Expect(refs).To(BeEmpty())
6161
}

pkg/services/govmomi/extra/extra_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func ConfigInitFnTester(method ConfigInitFn, methodName string, dataKey string,
9191
method(&config, sampleData)
9292

9393
It("must set 2 keys in the config", func() {
94-
Expect(len(config)).To(Equal(2))
94+
Expect(config).To(HaveLen(2))
9595
})
9696

9797
It(fmt.Sprintf("must set data as a base64 encoded string with the key %q", dataKey), func() {

pkg/services/govmomi/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func Test_ShouldRetryTask(t *testing.T) {
103103
reconciled, err := checkAndRetryTask(vmCtx, &task)
104104
g.Expect(err).NotTo(HaveOccurred())
105105
g.Expect(reconciled).To(BeTrue())
106-
g.Expect(conditions.IsFalse(vmCtx.VSphereVM, infrav1.VMProvisionedCondition))
106+
g.Expect(conditions.IsFalse(vmCtx.VSphereVM, infrav1.VMProvisionedCondition)).To(BeTrue())
107107
g.Expect(vmCtx.VSphereVM.Status.TaskRef).To(BeEmpty())
108108
g.Expect(vmCtx.VSphereVM.Status.RetryAfter.IsZero()).To(BeTrue())
109109
})
@@ -123,7 +123,7 @@ func Test_ShouldRetryTask(t *testing.T) {
123123
reconciled, err := checkAndRetryTask(vmCtx, &task)
124124
g.Expect(err).NotTo(HaveOccurred())
125125
g.Expect(reconciled).To(BeTrue())
126-
g.Expect(conditions.IsFalse(vmCtx.VSphereVM, infrav1.VMProvisionedCondition))
126+
g.Expect(conditions.IsFalse(vmCtx.VSphereVM, infrav1.VMProvisionedCondition)).To(BeTrue())
127127
g.Expect(vmCtx.VSphereVM.Status.RetryAfter.Unix()).To(BeNumerically("<=", metav1.Now().Add(1*time.Minute).Unix()))
128128
})
129129
}

0 commit comments

Comments
 (0)