Skip to content

🌱 Removed disabled usetesting in golangci.yaml, fixing linting issues #3503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ linters:
- usestdlibvars # using variables/constants from the standard library
- usetesting # report function to be replace by testing
- whitespace # unnecessary newlines
disable:
# TODO: It will be dropped when the Go version migration is done.
- usetesting
settings:
ginkgolinter:
forbid-focus-container: true
Expand Down
3 changes: 1 addition & 2 deletions controllers/vmware/vspherecluster_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package vmware

import (
"context"
"reflect"
"testing"

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

func TestClusterReconciler_getFailureDomains(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
ctx := t.Context()

scheme := runtime.NewScheme()
g.Expect(corev1.AddToScheme(scheme)).To(Succeed())
Expand Down
3 changes: 1 addition & 2 deletions controllers/vmware/vspheremachinetemplate_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package vmware

import (
"context"
"testing"

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

func Test_vSphereMachineTemplateReconciler_Reconcile(t *testing.T) {
g := NewWithT(t)
ctx := context.Background()
ctx := t.Context()

scheme := runtime.NewScheme()
g.Expect(corev1.AddToScheme(scheme)).To(Succeed())
Expand Down
33 changes: 16 additions & 17 deletions controllers/vspherevm_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package controllers

import (
"context"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -199,14 +198,14 @@ func TestReconcileNormal_WaitingForIPAddrAllocation(t *testing.T) {
r := setupReconciler(fakeVMSvc)
g := NewWithT(t)
// First reconcile should add the paused condition
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).NotTo(HaveOccurred())
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).NotTo(HaveOccurred())

vm := &infrav1.VSphereVM{}
vmKey := util.ObjectKey(vsphereVM)
g.Expect(r.Client.Get(context.Background(), vmKey, vm)).NotTo(HaveOccurred())
g.Expect(r.Client.Get(t.Context(), vmKey, vm)).NotTo(HaveOccurred())

g.Expect(v1beta1conditions.Has(vm, infrav1.VMProvisionedCondition)).To(BeTrue())
vmProvisionCondition := v1beta1conditions.Get(vm, infrav1.VMProvisionedCondition)
Expand Down Expand Up @@ -235,14 +234,14 @@ func TestReconcileNormal_WaitingForIPAddrAllocation(t *testing.T) {
r := setupReconciler(fakeVMSvc)
g := NewWithT(t)
// First reconcile should add the paused condition
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).NotTo(HaveOccurred())
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).NotTo(HaveOccurred())

vm := &infrav1.VSphereVM{}
vmKey := util.ObjectKey(vsphereVM)
g.Expect(r.Client.Get(context.Background(), vmKey, vm)).NotTo(HaveOccurred())
g.Expect(r.Client.Get(t.Context(), vmKey, vm)).NotTo(HaveOccurred())

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

// First reconcile should add the paused condition
_, err := r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err := r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).ToNot(HaveOccurred())
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).ToNot(HaveOccurred())

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

claim := &ipamv1beta1.IPAddressClaim{}
ipacKey := util.ObjectKey(ipAddressClaim)
g.Expect(r.Client.Get(context.Background(), ipacKey, claim)).NotTo(HaveOccurred())
g.Expect(r.Client.Get(t.Context(), ipacKey, claim)).NotTo(HaveOccurred())
g.Expect(claim.ObjectMeta.Finalizers).NotTo(ContainElement(infrav1.IPAddressClaimFinalizer))
})
}
Expand Down Expand Up @@ -369,7 +368,7 @@ func TestVmReconciler_WaitingForStaticIPAllocation(t *testing.T) {
}

controllerManagerCtx := fake.NewControllerManagerContext()
vmContext := fake.NewVMContext(context.Background(), controllerManagerCtx)
vmContext := fake.NewVMContext(t.Context(), controllerManagerCtx)
r := vmReconciler{ControllerManagerContext: controllerManagerCtx}

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

g := NewWithT(t)
// First reconcile should add the paused condition
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).NotTo(HaveOccurred())
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).NotTo(HaveOccurred())

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

g := NewWithT(t)
// First reconcile should add the paused condition
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).ToNot(HaveOccurred())
_, err = r.Reconcile(context.Background(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
_, err = r.Reconcile(t.Context(), ctrl.Request{NamespacedName: util.ObjectKey(vsphereVM)})
g.Expect(err).To(HaveOccurred())
},
)
Expand Down
3 changes: 1 addition & 2 deletions controllers/vspherevm_ipaddress_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package controllers

import (
"context"
"testing"

"github.com/onsi/gomega"
Expand Down Expand Up @@ -45,7 +44,7 @@ func Test_vmReconciler_reconcileIPAddressClaims(t *testing.T) {
VSphereVM: vsphereVM,
}
}
ctx := context.Background()
ctx := t.Context()

t.Run("when VSphereVM Spec has address pool references", func(t *testing.T) {
vsphereVM := &infrav1.VSphereVM{
Expand Down
8 changes: 4 additions & 4 deletions hack/tools/pkg/janitor/janitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const (
)

func Test_janitor_deleteVSphereVMs(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
ctx = ctrl.LoggerInto(ctx, klog.Background())

// Initialize and start vcsim
Expand Down Expand Up @@ -191,7 +191,7 @@ func Test_janitor_deleteVSphereVMs(t *testing.T) {
}

func Test_janitor_deleteObjectChildren(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
ctx = ctrl.LoggerInto(ctx, klog.Background())

// Initialize and start vcsim
Expand Down Expand Up @@ -322,7 +322,7 @@ func Test_janitor_deleteObjectChildren(t *testing.T) {
}

func TestJanitor_deleteCNSVolumes(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
ctx = ctrl.LoggerInto(ctx, klog.Background())

// Initialize and start vcsim
Expand Down Expand Up @@ -389,7 +389,7 @@ func TestJanitor_deleteCNSVolumes(t *testing.T) {
}

func Test_janitor_CleanupVSphere(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
ctx = ctrl.LoggerInto(ctx, klog.Background())

// Initialize and start vcsim
Expand Down
3 changes: 1 addition & 2 deletions internal/webhooks/vmware/vspheremachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package vmware

import (
"context"
"testing"

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

webhook := &VSphereMachine{}
_, err := webhook.ValidateUpdate(context.Background(), tc.oldVSphereMachine, tc.vsphereMachine)
_, err := webhook.ValidateUpdate(t.Context(), tc.oldVSphereMachine, tc.vsphereMachine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
3 changes: 1 addition & 2 deletions internal/webhooks/vmware/vspheremachinetemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package vmware

import (
"context"
"testing"

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

webhook := &VSphereMachineTemplate{}
_, err := webhook.validate(context.Background(), nil, vSphereMachineTemplate)
_, err := webhook.validate(t.Context(), nil, vSphereMachineTemplate)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
3 changes: 1 addition & 2 deletions internal/webhooks/vspheredeploymentzone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package webhooks

import (
"context"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -56,7 +55,7 @@ func TestVSphereDeploymentZone_Default(t *testing.T) {
},
}
webhook := VSphereDeploymentZone{}
g.Expect(webhook.Default(context.Background(), &vdz)).NotTo(HaveOccurred())
g.Expect(webhook.Default(t.Context(), &vdz)).NotTo(HaveOccurred())
g.Expect(vdz.Spec.ControlPlane).NotTo(BeNil())
g.Expect(*vdz.Spec.ControlPlane).To(Equal(tt.expectedVal))
})
Expand Down
5 changes: 2 additions & 3 deletions internal/webhooks/vspherefailuredomain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package webhooks

import (
"context"
"testing"

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

g.Expect(*m.Spec.Zone.AutoConfigure).To(BeFalse())
g.Expect(*m.Spec.Region.AutoConfigure).To(BeFalse())
Expand Down Expand Up @@ -160,7 +159,7 @@ func TestVSphereFailureDomain_ValidateCreate(t *testing.T) {
tt := tt
t.Run(tt.name, func(*testing.T) {
webhook := &VSphereFailureDomain{}
_, err := webhook.ValidateCreate(context.Background(), &tt.failureDomain)
_, err := webhook.ValidateCreate(t.Context(), &tt.failureDomain)
if tt.errExpected == nil || *tt.errExpected {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
7 changes: 3 additions & 4 deletions internal/webhooks/vspheremachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package webhooks

import (
"context"
"testing"

. "github.com/onsi/gomega"
Expand All @@ -35,7 +34,7 @@ func TestVsphereMachine_Default(t *testing.T) {
Spec: infrav1.VSphereMachineSpec{},
}
webhook := &VSphereMachine{}
g.Expect(webhook.Default(context.Background(), m)).ToNot(HaveOccurred())
g.Expect(webhook.Default(t.Context(), m)).ToNot(HaveOccurred())

g.Expect(m.Spec.Datacenter).To(Equal("*"))
}
Expand Down Expand Up @@ -135,7 +134,7 @@ func TestVSphereMachine_ValidateCreate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(*testing.T) {
webhook := &VSphereMachine{}
_, err := webhook.ValidateCreate(context.Background(), tc.vsphereMachine)
_, err := webhook.ValidateCreate(t.Context(), tc.vsphereMachine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down Expand Up @@ -212,7 +211,7 @@ func TestVSphereMachine_ValidateUpdate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(*testing.T) {
webhook := &VSphereMachine{}
_, err := webhook.ValidateUpdate(context.Background(), tc.oldVSphereMachine, tc.vsphereMachine)
_, err := webhook.ValidateUpdate(t.Context(), tc.oldVSphereMachine, tc.vsphereMachine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
5 changes: 2 additions & 3 deletions internal/webhooks/vspheremachinetemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package webhooks

import (
"context"
"testing"

. "github.com/onsi/gomega"
Expand Down Expand Up @@ -128,7 +127,7 @@ func TestVSphereMachineTemplate_ValidateCreate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(*testing.T) {
webhook := &VSphereMachineTemplate{}
_, err := webhook.ValidateCreate(context.Background(), tc.vsphereMachine)
_, err := webhook.ValidateCreate(t.Context(), tc.vsphereMachine)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down Expand Up @@ -200,7 +199,7 @@ func TestVSphereMachineTemplate_ValidateUpdate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(*testing.T) {
webhook := &VSphereMachineTemplate{}
ctx := context.Background()
ctx := t.Context()
if tc.req != nil {
ctx = admission.NewContextWithRequest(ctx, *tc.req)
}
Expand Down
7 changes: 3 additions & 4 deletions internal/webhooks/vspherevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package webhooks

import (
"context"
"testing"

. "github.com/onsi/gomega"
Expand All @@ -40,7 +39,7 @@ func TestVSphereVM_Default(t *testing.T) {
LinuxVM := createVSphereVM(linuxVMName, "foo.com", "", "", "", []string{"192.168.0.1/32", "192.168.0.3/32"}, nil, infrav1.Linux, infrav1.VirtualMachinePowerOpModeTrySoft, nil)
NoOSVM := createVSphereVM(linuxVMName, "foo.com", "", "", "", []string{"192.168.0.1/32", "192.168.0.3/32"}, nil, "", infrav1.VirtualMachinePowerOpModeTrySoft, nil)

ctx := context.Background()
ctx := t.Context()
webhook := &VSphereVM{}
g.Expect(webhook.Default(ctx, WindowsVM)).ToNot(HaveOccurred())
g.Expect(webhook.Default(ctx, LinuxVM)).ToNot(HaveOccurred())
Expand Down Expand Up @@ -118,7 +117,7 @@ func TestVSphereVM_ValidateCreate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(*testing.T) {
webhook := &VSphereVM{}
_, err := webhook.ValidateCreate(context.Background(), tc.vSphereVM)
_, err := webhook.ValidateCreate(t.Context(), tc.vSphereVM)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down Expand Up @@ -213,7 +212,7 @@ func TestVSphereVM_ValidateUpdate(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(*testing.T) {
webhook := &VSphereVM{}
_, err := webhook.ValidateUpdate(context.Background(), tc.oldVSphereVM, tc.vSphereVM)
_, err := webhook.ValidateUpdate(t.Context(), tc.oldVSphereVM, tc.vSphereVM)
if tc.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
Expand Down
Loading