From 226a4c1138df8bd55ae38558e43ffce15063e4e1 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Thu, 17 Oct 2024 08:12:57 +0200 Subject: [PATCH] golangci-lint: enable and fix thelper linter Signed-off-by: Matthieu MOREL --- .golangci.yaml | 1 + internal/restartabletest/restartable_delegate.go | 1 + internal/velero/images_test.go | 1 + pkg/controller/backup_deletion_controller_test.go | 1 + pkg/controller/backup_repository_controller_test.go | 1 + pkg/plugin/clientmgmt/manager_test.go | 1 + pkg/restore/restore_test.go | 1 + pkg/test/comparisons.go | 4 ++++ pkg/test/fake_controller_runtime_client.go | 3 +++ pkg/test/tar_writer.go | 1 + 10 files changed, 15 insertions(+) diff --git a/.golangci.yaml b/.golangci.yaml index 4c414b8439..9cd6081504 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -314,6 +314,7 @@ linters: - staticcheck - stylecheck - testifylint + - thelper - typecheck - unconvert - unparam diff --git a/internal/restartabletest/restartable_delegate.go b/internal/restartabletest/restartable_delegate.go index 37f73e4c39..e97d5fc7c0 100644 --- a/internal/restartabletest/restartable_delegate.go +++ b/internal/restartabletest/restartable_delegate.go @@ -75,6 +75,7 @@ func RunRestartableDelegateTests( newMock func() Mockable, tests ...RestartableDelegateTest, ) { + t.Helper() for _, tc := range tests { t.Run(tc.Function, func(t *testing.T) { p := new(MockRestartableProcess) diff --git a/internal/velero/images_test.go b/internal/velero/images_test.go index ad73452930..4e63dc543d 100644 --- a/internal/velero/images_test.go +++ b/internal/velero/images_test.go @@ -86,6 +86,7 @@ func TestImageRegistry(t *testing.T) { } func testDefaultImage(t *testing.T, defaultImageFn func() string, imageName string) { + t.Helper() testCases := []struct { name string buildInfoVersion string diff --git a/pkg/controller/backup_deletion_controller_test.go b/pkg/controller/backup_deletion_controller_test.go index 426ee000ce..9a85a13481 100644 --- a/pkg/controller/backup_deletion_controller_test.go +++ b/pkg/controller/backup_deletion_controller_test.go @@ -77,6 +77,7 @@ func defaultTestDbr() *velerov1api.DeleteBackupRequest { } func setupBackupDeletionControllerTest(t *testing.T, req *velerov1api.DeleteBackupRequest, objects ...runtime.Object) *backupDeletionControllerTestData { + t.Helper() var ( fakeClient = velerotest.NewFakeControllerRuntimeClient(t, append(objects, req)...) volumeSnapshotter = &velerotest.FakeVolumeSnapshotter{SnapshotsTaken: sets.NewString()} diff --git a/pkg/controller/backup_repository_controller_test.go b/pkg/controller/backup_repository_controller_test.go index 3dab5efa74..89b63e9eee 100644 --- a/pkg/controller/backup_repository_controller_test.go +++ b/pkg/controller/backup_repository_controller_test.go @@ -38,6 +38,7 @@ import ( const testMaintenanceFrequency = 10 * time.Minute func mockBackupRepoReconciler(t *testing.T, mockOn string, arg interface{}, ret interface{}) *BackupRepoReconciler { + t.Helper() mgr := &repomokes.Manager{} if mockOn != "" { mgr.On(mockOn, arg).Return(ret) diff --git a/pkg/plugin/clientmgmt/manager_test.go b/pkg/plugin/clientmgmt/manager_test.go index 6919fc9c36..8e15bbf503 100644 --- a/pkg/plugin/clientmgmt/manager_test.go +++ b/pkg/plugin/clientmgmt/manager_test.go @@ -282,6 +282,7 @@ func getPluginTest( expectedResultFunc func(name string, sharedPluginProcess process.RestartableProcess) interface{}, reinitializable bool, ) { + t.Helper() logger := test.NewLogger() logLevel := logrus.InfoLevel diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index 8e239e9a70..311d68cd47 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -3576,6 +3576,7 @@ func Test_getOrderedResources(t *testing.T) { // order. Any resources *not* in resourcePriorities are required to come *after* all // resources in any order. func assertResourceCreationOrder(t *testing.T, resourcePriorities []string, createdResources []resourceID) { + t.Helper() // lastSeen tracks the index in 'resourcePriorities' of the last resource type // we saw created. Once we've seen a resource in 'resourcePriorities', we should // never see another instance of a prior resource. diff --git a/pkg/test/comparisons.go b/pkg/test/comparisons.go index 677c39449e..4a0e415739 100644 --- a/pkg/test/comparisons.go +++ b/pkg/test/comparisons.go @@ -39,6 +39,7 @@ import ( // corresponding expected Action, and that each expected Action // has a corresponding actual Action. func CompareActions(t *testing.T, expected, actual []core.Action) { + t.Helper() assert.Len(t, actual, len(expected)) for _, e := range expected { @@ -73,6 +74,7 @@ func CompareActions(t *testing.T, expected, actual []core.Action) { // with the provided decode func and has no extraneous fields, and that // the decoded patch matches the expected. func ValidatePatch(t *testing.T, action core.Action, expected interface{}, decodeFunc func(*json.Decoder) (interface{}, error)) { + t.Helper() patchAction, ok := action.(core.PatchAction) require.True(t, ok, "action is not a PatchAction") @@ -96,6 +98,7 @@ func TimesAreEqual(t1, t2 time.Time) bool { // This function exists in order to make sure time.Time and metav1.Time objects // can be compared correctly. See https://github.com/stretchr/testify/issues/502. func AssertDeepEqual(t *testing.T, expected, actual interface{}) bool { + t.Helper() // By default, the equality.Semantic object doesn't have a function for comparing time.Times err := equality.Semantic.AddFunc(TimesAreEqual) if err != nil { @@ -114,6 +117,7 @@ func AssertDeepEqual(t *testing.T, expected, actual interface{}) bool { // AssertErrorMatches asserts that if expected is the empty string, actual // is nil, otherwise, that actual's error string matches expected. func AssertErrorMatches(t *testing.T, expected string, actual error) bool { + t.Helper() if expected != "" { return assert.EqualError(t, actual, expected) } diff --git a/pkg/test/fake_controller_runtime_client.go b/pkg/test/fake_controller_runtime_client.go index ec04324938..836cb7c3c2 100644 --- a/pkg/test/fake_controller_runtime_client.go +++ b/pkg/test/fake_controller_runtime_client.go @@ -33,6 +33,7 @@ import ( ) func NewFakeControllerRuntimeClientBuilder(t *testing.T) *k8sfake.ClientBuilder { + t.Helper() scheme := runtime.NewScheme() require.NoError(t, velerov1api.AddToScheme(scheme)) @@ -46,6 +47,7 @@ func NewFakeControllerRuntimeClientBuilder(t *testing.T) *k8sfake.ClientBuilder } func NewFakeControllerRuntimeClient(t *testing.T, initObjs ...runtime.Object) client.Client { + t.Helper() scheme := runtime.NewScheme() require.NoError(t, velerov1api.AddToScheme(scheme)) @@ -62,5 +64,6 @@ func NewFakeControllerRuntimeWatchClient( t *testing.T, initObjs ...runtime.Object, ) client.WithWatch { + t.Helper() return NewFakeControllerRuntimeClientBuilder(t).WithRuntimeObjects(initObjs...).Build() } diff --git a/pkg/test/tar_writer.go b/pkg/test/tar_writer.go index 8dc2f43b9e..6cfcd8bd7c 100644 --- a/pkg/test/tar_writer.go +++ b/pkg/test/tar_writer.go @@ -40,6 +40,7 @@ type TarWriter struct { } func NewTarWriter(t *testing.T) *TarWriter { + t.Helper() tw := new(TarWriter) tw.t = t tw.buf = new(bytes.Buffer)