From 59825a05065fc5a0f91eab74236cb17477d190f4 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sun, 1 Jun 2025 21:34:33 +0200 Subject: [PATCH] fix len rule from testifylint Signed-off-by: Matthieu MOREL --- .golangci.yaml | 1 - internal/restartabletest/restartable_delegate.go | 2 +- pkg/cmd/util/flag/orlabelselector_test.go | 2 +- pkg/cmd/util/output/backup_printer_test.go | 2 +- pkg/controller/backup_deletion_controller_test.go | 2 +- pkg/repository/provider/unified_repo_test.go | 2 +- pkg/restore/restore_test.go | 6 +++--- pkg/util/collections/includes_excludes_test.go | 4 ++-- pkg/util/logging/error_location_hook_test.go | 2 +- 9 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index d20c974e3..0561290e4 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -264,7 +264,6 @@ linters: - equal-values # FIXME - float-compare - go-require - - len # FIXME - require-error enable-all: true diff --git a/internal/restartabletest/restartable_delegate.go b/internal/restartabletest/restartable_delegate.go index d9308572e..af745773d 100644 --- a/internal/restartabletest/restartable_delegate.go +++ b/internal/restartabletest/restartable_delegate.go @@ -103,7 +103,7 @@ func RunRestartableDelegateTests( // This Function asserts that the actual outputs match the expected outputs checkOutputs := func(expected []any, actual []reflect.Value) { - require.Equal(t, len(expected), len(actual)) + require.Len(t, actual, len(expected)) for i := range actual { // Get the underlying value from the reflect.Value diff --git a/pkg/cmd/util/flag/orlabelselector_test.go b/pkg/cmd/util/flag/orlabelselector_test.go index bc395ba09..6f5598ab1 100644 --- a/pkg/cmd/util/flag/orlabelselector_test.go +++ b/pkg/cmd/util/flag/orlabelselector_test.go @@ -90,7 +90,7 @@ func TestSetOfOrLabelSelector(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { require.NoError(t, selector.Set(test.inputStr)) - assert.Equal(t, len(test.expectedSelector.OrLabelSelectors), len(selector.OrLabelSelectors)) + assert.Len(t, selector.OrLabelSelectors, len(test.expectedSelector.OrLabelSelectors)) assert.Equal(t, test.expectedSelector.String(), selector.String()) }) } diff --git a/pkg/cmd/util/output/backup_printer_test.go b/pkg/cmd/util/output/backup_printer_test.go index 00e8abc2a..1a00bf6c1 100644 --- a/pkg/cmd/util/output/backup_printer_test.go +++ b/pkg/cmd/util/output/backup_printer_test.go @@ -78,7 +78,7 @@ func TestSortBackups(t *testing.T) { t.Run(test.name, func(t *testing.T) { sortBackupsByPrefixAndTimestamp(test.backupList) - if assert.Equal(t, len(test.backupList.Items), len(test.expected)) { + if assert.Len(t, test.backupList.Items, len(test.expected)) { for i := range test.expected { assert.Equal(t, test.expected[i].Name, test.backupList.Items[i].Name) } diff --git a/pkg/controller/backup_deletion_controller_test.go b/pkg/controller/backup_deletion_controller_test.go index 142c4af43..7c651949e 100644 --- a/pkg/controller/backup_deletion_controller_test.go +++ b/pkg/controller/backup_deletion_controller_test.go @@ -1070,7 +1070,7 @@ func TestDeleteMovedSnapshots(t *testing.T) { if test.expected == nil { assert.Nil(t, errs) } else { - assert.Equal(t, len(test.expected), len(errs)) + assert.Len(t, errs, len(test.expected)) for i := range test.expected { assert.EqualError(t, errs[i], test.expected[i]) } diff --git a/pkg/repository/provider/unified_repo_test.go b/pkg/repository/provider/unified_repo_test.go index 9a4e98f0d..5f3bdbe4b 100644 --- a/pkg/repository/provider/unified_repo_test.go +++ b/pkg/repository/provider/unified_repo_test.go @@ -1083,7 +1083,7 @@ func TestBatchForget(t *testing.T) { if tc.expectedErr == nil { assert.Empty(t, errs) } else { - assert.Equal(t, len(tc.expectedErr), len(errs)) + assert.Len(t, errs, len(tc.expectedErr)) for i := range tc.expectedErr { assert.EqualError(t, errs[i], tc.expectedErr[i]) diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index a28a8ba62..75dd8f9df 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -1028,15 +1028,15 @@ func TestInvalidTarballContents(t *testing.T) { func assertWantErrsOrWarnings(t *testing.T, wantRes Result, res Result) { t.Helper() if wantRes.Velero != nil { - assert.Equal(t, len(wantRes.Velero), len(res.Velero)) + assert.Len(t, res.Velero, len(wantRes.Velero)) for i := range res.Velero { assert.Contains(t, res.Velero[i], wantRes.Velero[i]) } } if wantRes.Namespaces != nil { - assert.Equal(t, len(wantRes.Namespaces), len(res.Namespaces)) + assert.Len(t, res.Namespaces, len(wantRes.Namespaces)) for ns := range res.Namespaces { - assert.Equal(t, len(wantRes.Namespaces[ns]), len(res.Namespaces[ns])) + assert.Len(t, res.Namespaces[ns], len(wantRes.Namespaces[ns])) for i := range res.Namespaces[ns] { assert.Contains(t, res.Namespaces[ns][i], wantRes.Namespaces[ns][i]) } diff --git a/pkg/util/collections/includes_excludes_test.go b/pkg/util/collections/includes_excludes_test.go index 655e3a50e..a3466066c 100644 --- a/pkg/util/collections/includes_excludes_test.go +++ b/pkg/util/collections/includes_excludes_test.go @@ -160,7 +160,7 @@ func TestValidateIncludesExcludes(t *testing.T) { t.Run(tc.name, func(t *testing.T) { errs := ValidateIncludesExcludes(tc.includes, tc.excludes) - require.Equal(t, len(tc.want), len(errs)) + require.Len(t, errs, len(tc.want)) for i := 0; i < len(tc.want); i++ { assert.Equal(t, tc.want[i].Error(), errs[i].Error()) @@ -361,7 +361,7 @@ func TestValidateScopedIncludesExcludes(t *testing.T) { t.Run(tc.name, func(t *testing.T) { errs := ValidateScopedIncludesExcludes(tc.includes, tc.excludes) - require.Equal(t, len(tc.wantErr), len(errs)) + require.Len(t, errs, len(tc.wantErr)) for i := 0; i < len(tc.wantErr); i++ { assert.Equal(t, tc.wantErr[i].Error(), errs[i].Error()) diff --git a/pkg/util/logging/error_location_hook_test.go b/pkg/util/logging/error_location_hook_test.go index 606c6e525..f63254c78 100644 --- a/pkg/util/logging/error_location_hook_test.go +++ b/pkg/util/logging/error_location_hook_test.go @@ -85,7 +85,7 @@ func TestFire(t *testing.T) { err := hook.Fire(entry) require.Equal(t, test.expectedErr, err != nil) - require.Equal(t, len(test.expectedEntryFields), len(entry.Data)) + require.Len(t, entry.Data, len(test.expectedEntryFields)) for key, expectedValue := range test.expectedEntryFields { actualValue, found := entry.Data[key]