Skip to content

Commit a33fbfa

Browse files
committed
removing disabled usetesting, fixing various linting issues in test files
1 parent 3333b08 commit a33fbfa

30 files changed

+66
-92
lines changed

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ linters:
4343
- usestdlibvars # using variables/constants from the standard library
4444
- usetesting # report function to be replace by testing
4545
- whitespace # unnecessary newlines
46-
disable:
47-
# TODO: It will be dropped when the Go version migration is done.
48-
- usetesting
4946
settings:
5047
ginkgolinter:
5148
forbid-focus-container: true

controllers/vmware/vspherecluster_reconciler_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package vmware
1818

1919
import (
20-
"context"
2120
"reflect"
2221
"testing"
2322

@@ -126,7 +125,7 @@ var _ = Describe("Cluster Controller Tests", func() {
126125

127126
func TestClusterReconciler_getFailureDomains(t *testing.T) {
128127
g := NewWithT(t)
129-
ctx := context.Background()
128+
ctx := t.Context()
130129

131130
scheme := runtime.NewScheme()
132131
g.Expect(corev1.AddToScheme(scheme)).To(Succeed())

controllers/vmware/vspheremachinetemplate_controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package vmware
1818

1919
import (
20-
"context"
2120
"testing"
2221

2322
. "github.com/onsi/gomega"
@@ -36,7 +35,7 @@ import (
3635

3736
func Test_vSphereMachineTemplateReconciler_Reconcile(t *testing.T) {
3837
g := NewWithT(t)
39-
ctx := context.Background()
38+
ctx := t.Context()
4039

4140
scheme := runtime.NewScheme()
4241
g.Expect(corev1.AddToScheme(scheme)).To(Succeed())

controllers/vspherevm_controller_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20-
"context"
2120
"fmt"
2221
"testing"
2322
"time"
@@ -199,14 +198,14 @@ func TestReconcileNormal_WaitingForIPAddrAllocation(t *testing.T) {
199198
r := setupReconciler(fakeVMSvc)
200199
g := NewWithT(t)
201200
// First reconcile should add the paused condition
202-
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
201+
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
203202
g.Expect(err).NotTo(HaveOccurred())
204-
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
203+
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
205204
g.Expect(err).NotTo(HaveOccurred())
206205

207206
vm := &infrav1.VSphereVM{}
208207
vmKey := util.ObjectKey(vsphereVM)
209-
g.Expect(r.Client.Get(context.Background(), vmKey, vm)).NotTo(HaveOccurred())
208+
g.Expect(r.Client.Get(t.Context(), vmKey, vm)).NotTo(HaveOccurred())
210209

211210
g.Expect(v1beta1conditions.Has(vm, infrav1.VMProvisionedCondition)).To(BeTrue())
212211
vmProvisionCondition := v1beta1conditions.Get(vm, infrav1.VMProvisionedCondition)
@@ -235,14 +234,14 @@ func TestReconcileNormal_WaitingForIPAddrAllocation(t *testing.T) {
235234
r := setupReconciler(fakeVMSvc)
236235
g := NewWithT(t)
237236
// First reconcile should add the paused condition
238-
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
237+
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
239238
g.Expect(err).NotTo(HaveOccurred())
240-
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
239+
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
241240
g.Expect(err).NotTo(HaveOccurred())
242241

243242
vm := &infrav1.VSphereVM{}
244243
vmKey := util.ObjectKey(vsphereVM)
245-
g.Expect(r.Client.Get(context.Background(), vmKey, vm)).NotTo(HaveOccurred())
244+
g.Expect(r.Client.Get(t.Context(), vmKey, vm)).NotTo(HaveOccurred())
246245

247246
g.Expect(v1beta1conditions.Has(vm, infrav1.VMProvisionedCondition)).To(BeTrue())
248247
vmProvisionCondition := v1beta1conditions.Get(vm, infrav1.VMProvisionedCondition)
@@ -285,18 +284,18 @@ func TestReconcileNormal_WaitingForIPAddrAllocation(t *testing.T) {
285284
g := NewWithT(t)
286285

287286
// First reconcile should add the paused condition
288-
_, err := r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
287+
_, err := r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
289288
g.Expect(err).ToNot(HaveOccurred())
290-
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
289+
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
291290
g.Expect(err).ToNot(HaveOccurred())
292291

293292
vm := &infrav1.VSphereVM{}
294293
vmKey := util.ObjectKey(vsphereVM)
295-
g.Expect(apierrors.IsNotFound(r.Client.Get(context.Background(), vmKey, vm))).To(BeTrue())
294+
g.Expect(apierrors.IsNotFound(r.Client.Get(t.Context(), vmKey, vm))).To(BeTrue())
296295

297296
claim := &ipamv1beta1.IPAddressClaim{}
298297
ipacKey := util.ObjectKey(ipAddressClaim)
299-
g.Expect(r.Client.Get(context.Background(), ipacKey, claim)).NotTo(HaveOccurred())
298+
g.Expect(r.Client.Get(t.Context(), ipacKey, claim)).NotTo(HaveOccurred())
300299
g.Expect(claim.ObjectMeta.Finalizers).NotTo(ContainElement(infrav1.IPAddressClaimFinalizer))
301300
})
302301
}
@@ -369,7 +368,7 @@ func TestVmReconciler_WaitingForStaticIPAllocation(t *testing.T) {
369368
}
370369

371370
controllerManagerCtx := fake.NewControllerManagerContext()
372-
vmContext := fake.NewVMContext(context.Background(), controllerManagerCtx)
371+
vmContext := fake.NewVMContext(t.Context(), controllerManagerCtx)
373372
r := vmReconciler{ControllerManagerContext: controllerManagerCtx}
374373

375374
for _, tt := range tests {
@@ -492,14 +491,14 @@ func TestRetrievingVCenterCredentialsFromCluster(t *testing.T) {
492491

493492
g := NewWithT(t)
494493
// First reconcile should add the paused condition
495-
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
494+
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
496495
g.Expect(err).NotTo(HaveOccurred())
497-
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
496+
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
498497
g.Expect(err).NotTo(HaveOccurred())
499498

500499
vm := &infrav1.VSphereVM{}
501500
vmKey := util.ObjectKey(vsphereVM)
502-
g.Expect(r.Client.Get(context.Background(), vmKey, vm)).NotTo(HaveOccurred())
501+
g.Expect(r.Client.Get(t.Context(), vmKey, vm)).NotTo(HaveOccurred())
503502
g.Expect(v1beta1conditions.Has(vm, infrav1.VCenterAvailableCondition)).To(BeTrue())
504503
vCenterCondition := v1beta1conditions.Get(vm, infrav1.VCenterAvailableCondition)
505504
g.Expect(vCenterCondition.Status).To(Equal(corev1.ConditionTrue))
@@ -529,9 +528,9 @@ func TestRetrievingVCenterCredentialsFromCluster(t *testing.T) {
529528

530529
g := NewWithT(t)
531530
// First reconcile should add the paused condition
532-
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
531+
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
533532
g.Expect(err).ToNot(HaveOccurred())
534-
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
533+
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
535534
g.Expect(err).To(HaveOccurred())
536535
},
537536
)

controllers/vspherevm_ipaddress_reconciler_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20-
"context"
2120
"testing"
2221

2322
"github.com/onsi/gomega"
@@ -45,7 +44,7 @@ func Test_vmReconciler_reconcileIPAddressClaims(t *testing.T) {
4544
VSphereVM: vsphereVM,
4645
}
4746
}
48-
ctx := context.Background()
47+
ctx := t.Context()
4948

5049
t.Run("when VSphereVM Spec has address pool references", func(t *testing.T) {
5150
vsphereVM := &infrav1.VSphereVM{

hack/tools/pkg/janitor/janitor_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const (
112112
)
113113

114114
func Test_janitor_deleteVSphereVMs(t *testing.T) {
115-
ctx := context.Background()
115+
ctx := t.Context()
116116
ctx = ctrl.LoggerInto(ctx, klog.Background())
117117

118118
// Initialize and start vcsim
@@ -191,7 +191,7 @@ func Test_janitor_deleteVSphereVMs(t *testing.T) {
191191
}
192192

193193
func Test_janitor_deleteObjectChildren(t *testing.T) {
194-
ctx := context.Background()
194+
ctx := t.Context()
195195
ctx = ctrl.LoggerInto(ctx, klog.Background())
196196

197197
// Initialize and start vcsim
@@ -322,7 +322,7 @@ func Test_janitor_deleteObjectChildren(t *testing.T) {
322322
}
323323

324324
func TestJanitor_deleteCNSVolumes(t *testing.T) {
325-
ctx := context.Background()
325+
ctx := t.Context()
326326
ctx = ctrl.LoggerInto(ctx, klog.Background())
327327

328328
// Initialize and start vcsim
@@ -389,7 +389,7 @@ func TestJanitor_deleteCNSVolumes(t *testing.T) {
389389
}
390390

391391
func Test_janitor_CleanupVSphere(t *testing.T) {
392-
ctx := context.Background()
392+
ctx := t.Context()
393393
ctx = ctrl.LoggerInto(ctx, klog.Background())
394394

395395
// Initialize and start vcsim

internal/webhooks/vmware/vspheremachine_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package vmware
1818

1919
import (
20-
"context"
2120
"testing"
2221

2322
. "github.com/onsi/gomega"
@@ -69,7 +68,7 @@ func TestVSphereMachine_ValidateUpdate(t *testing.T) {
6968
g := NewWithT(t)
7069

7170
webhook := &VSphereMachine{}
72-
_, err := webhook.ValidateUpdate(context.Background(), tc.oldVSphereMachine, tc.vsphereMachine)
71+
_, err := webhook.ValidateUpdate(t.Context(), tc.oldVSphereMachine, tc.vsphereMachine)
7372
if tc.wantErr {
7473
g.Expect(err).To(HaveOccurred())
7574
} else {

internal/webhooks/vmware/vspheremachinetemplate_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package vmware
1818

1919
import (
20-
"context"
2120
"testing"
2221

2322
. "github.com/onsi/gomega"
@@ -88,7 +87,7 @@ func TestVSphereMachineTemplate_Validate(t *testing.T) {
8887
}
8988

9089
webhook := &VSphereMachineTemplate{}
91-
_, err := webhook.validate(context.Background(), nil, vSphereMachineTemplate)
90+
_, err := webhook.validate(t.Context(), nil, vSphereMachineTemplate)
9291
if tc.wantErr {
9392
g.Expect(err).To(HaveOccurred())
9493
} else {

internal/webhooks/vspheredeploymentzone_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package webhooks
1818

1919
import (
20-
"context"
2120
"testing"
2221

2322
. "github.com/onsi/gomega"
@@ -56,7 +55,7 @@ func TestVSphereDeploymentZone_Default(t *testing.T) {
5655
},
5756
}
5857
webhook := VSphereDeploymentZone{}
59-
g.Expect(webhook.Default(context.Background(), &vdz)).NotTo(HaveOccurred())
58+
g.Expect(webhook.Default(t.Context(), &vdz)).NotTo(HaveOccurred())
6059
g.Expect(vdz.Spec.ControlPlane).NotTo(BeNil())
6160
g.Expect(*vdz.Spec.ControlPlane).To(Equal(tt.expectedVal))
6261
})

internal/webhooks/vspherefailuredomain_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package webhooks
1818

1919
import (
20-
"context"
2120
"testing"
2221

2322
. "github.com/onsi/gomega"
@@ -32,7 +31,7 @@ func TestVsphereFailureDomain_Default(t *testing.T) {
3231
Spec: infrav1.VSphereFailureDomainSpec{},
3332
}
3433
webhook := &VSphereFailureDomain{}
35-
g.Expect(webhook.Default(context.Background(), m)).ToNot(HaveOccurred())
34+
g.Expect(webhook.Default(t.Context(), m)).ToNot(HaveOccurred())
3635

3736
g.Expect(*m.Spec.Zone.AutoConfigure).To(BeFalse())
3837
g.Expect(*m.Spec.Region.AutoConfigure).To(BeFalse())
@@ -160,7 +159,7 @@ func TestVSphereFailureDomain_ValidateCreate(t *testing.T) {
160159
tt := tt
161160
t.Run(tt.name, func(*testing.T) {
162161
webhook := &VSphereFailureDomain{}
163-
_, err := webhook.ValidateCreate(context.Background(), &tt.failureDomain)
162+
_, err := webhook.ValidateCreate(t.Context(), &tt.failureDomain)
164163
if tt.errExpected == nil || *tt.errExpected {
165164
g.Expect(err).To(HaveOccurred())
166165
} else {

0 commit comments

Comments
 (0)