From 6a6a237ba738dc2b7025eebfc9b790fc2dc8497a Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Tue, 4 Mar 2025 09:25:29 +0100 Subject: [PATCH] Bump golangci-lint from v1.57.2 to v1.64.5 (#8641) Signed-off-by: Matthieu MOREL --- .github/workflows/pr-linter-check.yml | 2 +- .golangci.yaml | 70 ++++++++++++++----- hack/build-image/Dockerfile | 2 +- .../resourcepolicies/resource_policies.go | 2 +- .../resourcepolicies/volume_resources_test.go | 2 - internal/storage/storagelocation.go | 3 +- .../util/downloadrequest/downloadrequest.go | 2 +- pkg/controller/backup_deletion_controller.go | 2 +- pkg/controller/backup_sync_controller_test.go | 1 - .../data_download_controller_test.go | 4 +- pkg/controller/restore_controller.go | 4 +- .../actions/csi/volumesnapshot_action_test.go | 4 +- pkg/test/fake_discovery_helper.go | 4 +- pkg/util/kube/mocks.go | 3 +- pkg/util/kube/pvc_pv.go | 4 +- .../backup-volume-info/csi_data_mover.go | 2 +- .../basic/backup-volume-info/csi_snapshot.go | 2 +- .../backup-volume-info/filesystem_upload.go | 2 +- .../backup-volume-info/native_snapshot.go | 2 +- .../backup-volume-info/skipped_volumes.go | 2 +- .../resource-filtering/exclude_resources.go | 4 +- .../resource-filtering/include_resources.go | 4 +- test/e2e/resource-filtering/label_selector.go | 2 +- test/util/k8s/common.go | 2 +- test/util/kibishii/kibishii_utils.go | 6 +- test/util/providers/azure_utils.go | 2 +- test/util/providers/gcloud_utils.go | 6 +- 27 files changed, 87 insertions(+), 58 deletions(-) diff --git a/.github/workflows/pr-linter-check.yml b/.github/workflows/pr-linter-check.yml index 6578417a6..46113c6d3 100644 --- a/.github/workflows/pr-linter-check.yml +++ b/.github/workflows/pr-linter-check.yml @@ -20,5 +20,5 @@ jobs: - name: Linter check uses: golangci/golangci-lint-action@v6 with: - version: v1.57.2 + version: v1.64.5 args: --verbose diff --git a/.golangci.yaml b/.golangci.yaml index ec714ab58..331cf6679 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -27,7 +27,6 @@ run: # If false (default) - golangci-lint acquires file lock on start. allow-parallel-runners: false - # output configuration options output: # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" @@ -41,18 +40,25 @@ output: # print linter name in the end of issue text, default is true print-linter-name: true - # make issues output unique by line, default is true - uniq-by-line: true - - # all available settings of specific linters linters-settings: + + depguard: + rules: + main: + deny: + # specify an error message to output when a denylisted package is used + - pkg: github.com/sirupsen/logrus + desc: "logging is allowed only by logutils.Log" + dogsled: # checks assignments with too many blank identifiers; default is 2 max-blank-identifiers: 2 + dupl: # tokens count to trigger issue, 150 by default threshold: 100 + errcheck: # report about not checking of errors in type assertions: `a := b.(MyStruct)`; # default is false: such cases aren't reported by default. @@ -70,25 +76,31 @@ linters-settings: # path to a file containing a list of functions to exclude from checking # see https://github.com/kisielk/errcheck#excluding-functions for details # exclude: /path/to/file.txt + exhaustive: # indicates that switch statements are to be considered exhaustive if a # 'default' case is present, even if all enum members aren't listed in the # switch default-signifies-exhaustive: false + funlen: lines: 60 statements: 40 + gocognit: # minimal code complexity to report, 30 by default (but we recommend 10-20) min-complexity: 10 + nestif: # minimal complexity of if statements to report, 5 by default min-complexity: 4 + goconst: # minimal length of string constant, 3 by default min-len: 3 # minimal occurrences count to trigger, 3 by default min-occurrences: 5 + gocritic: # Which checks should be enabled; can't be combined with 'disabled-checks'; # See https://go-critic.github.io/overview#checks-overview @@ -113,12 +125,15 @@ linters-settings: paramsOnly: true # rangeValCopy: # sizeThreshold: 32 + gocyclo: # minimal code complexity to report, 30 by default (but we recommend 10-20) min-complexity: 10 + godot: # check all top-level comments, not only declarations check-all: false + godox: # report any comments starting with keywords, this is useful for TODO or FIXME comments that # might be left in the code accidentally and should be resolved before merging @@ -126,13 +141,20 @@ linters-settings: - NOTE - OPTIMIZE # marks code that should be optimized before merging - HACK # marks hack-arounds that should be removed before merging + gofmt: # simplify code: gofmt with `-s` option, true by default simplify: true + goimports: # put imports beginning with prefix after 3rd-party packages; # it's a comma-separated list of prefixes local-prefixes: github.com/org/project + + gosec: + excludes: + - G115 + govet: # report about shadowed variables # check-shadowing: true @@ -153,12 +175,14 @@ linters-settings: disable: - shadow disable-all: false + lll: # max line length, lines longer will be reported. Default is 120. # '\t' is counted as 1 character by default, and can be changed with the tab-width option line-length: 120 # tab width in spaces. Default to 1. tab-width: 1 + misspell: # Correct spellings using locale preferences for US or UK. # Default is to use a neutral variety of English. @@ -166,9 +190,11 @@ linters-settings: locale: US ignore-words: - someword + nakedret: # make an issue if func has more lines of code than this setting and it has naked returns; default is 30 max-func-lines: 30 + prealloc: # XXX: we don't recommend using this linter before doing performance profiling. # For most programs usage of prealloc will be a premature optimization. @@ -178,6 +204,7 @@ linters-settings: simple: true range-loops: true # Report preallocation suggestions on range loops, true by default for-loops: false # Report preallocation suggestions on for loops, false by default + nolintlint: # Enable to ensure that nolint directives are all used. Default is true. allow-unused: false @@ -187,11 +214,13 @@ linters-settings: require-explanation: true # Enable to require nolint directives to mention the specific linter being suppressed. Default is false. require-specific: true + perfsprint: strconcat: false sprintf1: false errorf: false int-conversion: true + revive: rules: - name: blank-imports @@ -238,10 +267,11 @@ linters-settings: - name: var-declaration - name: var-naming disabled: true - + rowserrcheck: packages: - github.com/jmoiron/sqlx + testifylint: # TODO: enable them all disable: @@ -249,6 +279,7 @@ linters-settings: - float-compare - require-error enable-all: true + testpackage: # regexp pattern to skip files skip-regexp: (export|internal)_test\.go @@ -258,9 +289,11 @@ linters-settings: # if it's called for subdir of a project it can't find external interfaces. All text editor integrations # with golangci-lint call it on a directory with the changed file. check-exported: false + whitespace: multi-if: false # Enforces newlines (or comments) after every multi-line if statement multi-func: false # Enforces newlines (or comments) after every multi-line function signature + wsl: # If true append is only allowed to be cuddled if appending value is # matching variables, fields or types on line above. Default is true. @@ -288,11 +321,11 @@ linters: - asciicheck - bidichk - bodyclose + - copyloopvar - dogsled - durationcheck - dupword - errcheck - - exportloopref - errchkjson - goconst - gofmt @@ -325,8 +358,16 @@ linters: - whitespace fast: false - issues: + # which dirs to skip: issues from them won't be reported; + # can use regexp here: generated.*, regexp is applied on full path; + # default value is empty list, but default dirs are skipped independently + # from this option's value (see skip-dirs-use-default). + # "/" will be replaced by current OS file path separator to properly work + # on Windows. + exclude-dirs: + - pkg/plugin/generated/* + exclude-rules: - linters: - staticcheck @@ -370,17 +411,8 @@ issues: # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. max-same-issues: 0 - # Show only new issues created after git revision `REV` - # new-from-rev: origin/main - - # which dirs to skip: issues from them won't be reported; - # can use regexp here: generated.*, regexp is applied on full path; - # default value is empty list, but default dirs are skipped independently - # from this option's value (see skip-dirs-use-default). - # "/" will be replaced by current OS file path separator to properly work - # on Windows. - exclude-dirs: - - pkg/plugin/generated/* + # make issues output unique by line, default is true + uniq-by-line: true severity: # Default value is empty string. diff --git a/hack/build-image/Dockerfile b/hack/build-image/Dockerfile index c5127faa7..a01c7f526 100644 --- a/hack/build-image/Dockerfile +++ b/hack/build-image/Dockerfile @@ -94,7 +94,7 @@ RUN ARCH=$(go env GOARCH) && \ chmod +x /usr/bin/goreleaser # get golangci-lint -RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2 +RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.5 # install kubectl RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/$(go env GOARCH)/kubectl diff --git a/internal/resourcepolicies/resource_policies.go b/internal/resourcepolicies/resource_policies.go index c4f9e4b8b..fd9791752 100644 --- a/internal/resourcepolicies/resource_policies.go +++ b/internal/resourcepolicies/resource_policies.go @@ -106,7 +106,7 @@ func (p *Policies) BuildPolicy(resPolicies *ResourcePolicies) error { volP.conditions = append(volP.conditions, &nfsCondition{nfs: con.NFS}) volP.conditions = append(volP.conditions, &csiCondition{csi: con.CSI}) volP.conditions = append(volP.conditions, &volumeTypeCondition{volumeTypes: con.VolumeTypes}) - if con.PVCLabels != nil && len(con.PVCLabels) > 0 { + if len(con.PVCLabels) > 0 { volP.conditions = append(volP.conditions, &pvcLabelsCondition{labels: con.PVCLabels}) } p.volumePolicies = append(p.volumePolicies, volP) diff --git a/internal/resourcepolicies/volume_resources_test.go b/internal/resourcepolicies/volume_resources_test.go index c93430b5b..b55692326 100644 --- a/internal/resourcepolicies/volume_resources_test.go +++ b/internal/resourcepolicies/volume_resources_test.go @@ -150,7 +150,6 @@ func TestParseCapacity(t *testing.T) { } for _, test := range tests { - test := test // capture range variable t.Run(test.input, func(t *testing.T) { actual, actualErr := parseCapacity(test.input) if test.expected != emptyCapacity { @@ -181,7 +180,6 @@ func TestCapacityIsInRange(t *testing.T) { } for _, test := range tests { - test := test // capture range variable t.Run(fmt.Sprintf("%v with %v", test.capacity, test.quantity), func(t *testing.T) { t.Parallel() diff --git a/internal/storage/storagelocation.go b/internal/storage/storagelocation.go index 006ce773e..d5fe548c0 100644 --- a/internal/storage/storagelocation.go +++ b/internal/storage/storagelocation.go @@ -18,7 +18,6 @@ package storage import ( "context" - "fmt" "time" "github.com/pkg/errors" @@ -98,7 +97,7 @@ func GetDefaultBackupStorageLocations(ctx context.Context, kbClient client.Clien locations := new(velerov1api.BackupStorageLocationList) defaultLocations := new(velerov1api.BackupStorageLocationList) if err := kbClient.List(context.Background(), locations, &client.ListOptions{Namespace: namespace}); err != nil { - return defaultLocations, errors.Wrapf(err, fmt.Sprintf("failed to list backup storage locations in namespace %s", namespace)) + return defaultLocations, errors.Wrapf(err, "failed to list backup storage locations in namespace %s", namespace) } for _, location := range locations.Items { diff --git a/pkg/cmd/util/downloadrequest/downloadrequest.go b/pkg/cmd/util/downloadrequest/downloadrequest.go index 7a85920fa..a76d2bb80 100644 --- a/pkg/cmd/util/downloadrequest/downloadrequest.go +++ b/pkg/cmd/util/downloadrequest/downloadrequest.go @@ -152,7 +152,7 @@ func download( if err != nil { if urlErr, ok := err.(*url.Error); ok { if _, ok := urlErr.Err.(x509.UnknownAuthorityError); ok { - return fmt.Errorf(err.Error() + "\n\nThe --insecure-skip-tls-verify flag can also be used to accept any TLS certificate for the download, but it is susceptible to man-in-the-middle attacks.") + return fmt.Errorf("%s\n\nThe --insecure-skip-tls-verify flag can also be used to accept any TLS certificate for the download, but it is susceptible to man-in-the-middle attacks", err.Error()) } } return err diff --git a/pkg/controller/backup_deletion_controller.go b/pkg/controller/backup_deletion_controller.go index 31874412d..30693959e 100644 --- a/pkg/controller/backup_deletion_controller.go +++ b/pkg/controller/backup_deletion_controller.go @@ -555,7 +555,7 @@ func (r *backupDeletionReconciler) deleteMovedSnapshots(ctx context.Context, bac directSnapshots := map[string][]repotypes.SnapshotIdentifier{} for i := range list.Items { cm := list.Items[i] - if cm.Data == nil || len(cm.Data) == 0 { + if len(cm.Data) == 0 { errs = append(errs, errors.New("no snapshot info in config")) continue } diff --git a/pkg/controller/backup_sync_controller_test.go b/pkg/controller/backup_sync_controller_test.go index 1bba44134..398165515 100644 --- a/pkg/controller/backup_sync_controller_test.go +++ b/pkg/controller/backup_sync_controller_test.go @@ -879,7 +879,6 @@ var _ = Describe("Backup Sync Reconciler", func() { }, } for _, test := range testCases { - test := test It(test.name, func() { logger := velerotest.NewLogger() b := backupSyncReconciler{ diff --git a/pkg/controller/data_download_controller_test.go b/pkg/controller/data_download_controller_test.go index 9c562d4fb..5ade3d218 100644 --- a/pkg/controller/data_download_controller_test.go +++ b/pkg/controller/data_download_controller_test.go @@ -514,12 +514,12 @@ func TestDataDownloadReconcile(t *testing.T) { } if test.dd.Namespace == velerov1api.DefaultNamespace { if controllerutil.ContainsFinalizer(test.dd, DataUploadDownloadFinalizer) { - assert.True(t, true, apierrors.IsNotFound(err)) + assert.True(t, true, apierrors.IsNotFound(err)) //nolint:testifylint //FIXME } else { require.NoError(t, err) } } else { - assert.True(t, true, apierrors.IsNotFound(err)) + assert.True(t, true, apierrors.IsNotFound(err)) //nolint:testifylint //FIXME } if !test.needCreateFSBR { diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index 72c846b66..248ccbc49 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -408,10 +408,10 @@ func (r *restoreReconciler) validateAndComplete(restore *api.Restore) (backupInf } resourceModifiers, err = resourcemodifiers.GetResourceModifiersFromConfig(ResourceModifierConfigMap) if err != nil { - restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, errors.Wrapf(err, fmt.Sprintf("Error in parsing resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name)).Error()) + restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, errors.Wrapf(err, "Error in parsing resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name).Error()) return backupInfo{}, nil } else if err = resourceModifiers.Validate(); err != nil { - restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, errors.Wrapf(err, fmt.Sprintf("Validation error in resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name)).Error()) + restore.Status.ValidationErrors = append(restore.Status.ValidationErrors, errors.Wrapf(err, "Validation error in resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name).Error()) return backupInfo{}, nil } r.logger.Infof("Retrieved Resource modifiers provided in configmap %s/%s", restore.Namespace, restore.Spec.ResourceModifier.Name) diff --git a/pkg/restore/actions/csi/volumesnapshot_action_test.go b/pkg/restore/actions/csi/volumesnapshot_action_test.go index 308c02895..e84079bee 100644 --- a/pkg/restore/actions/csi/volumesnapshot_action_test.go +++ b/pkg/restore/actions/csi/volumesnapshot_action_test.go @@ -89,12 +89,12 @@ func TestResetVolumeSnapshotSpecForRestore(t *testing.T) { resetVolumeSnapshotSpecForRestore(&tc.vs, &tc.vscName) assert.Equalf(t, tc.vs.Name, before.Name, "unexpected change to Object.Name, Want: %s; Got %s", before.Name, tc.vs.Name) - assert.Equal(t, tc.vs.Namespace, before.Namespace, "unexpected change to Object.Namespace, Want: %s; Got %s", tc.name, before.Namespace, tc.vs.Namespace) + assert.Equalf(t, tc.vs.Namespace, before.Namespace, "unexpected change to Object.Namespace, Want: %s; Got %s", before.Namespace, tc.vs.Namespace) assert.NotNil(t, tc.vs.Spec.Source) assert.Nil(t, tc.vs.Spec.Source.PersistentVolumeClaimName) assert.NotNil(t, tc.vs.Spec.Source.VolumeSnapshotContentName) assert.Equal(t, *tc.vs.Spec.Source.VolumeSnapshotContentName, tc.vscName) - assert.Equal(t, *tc.vs.Spec.VolumeSnapshotClassName, *before.Spec.VolumeSnapshotClassName, "unexpected value for Spec.VolumeSnapshotClassName, Want: %s, Got: %s", + assert.Equalf(t, *tc.vs.Spec.VolumeSnapshotClassName, *before.Spec.VolumeSnapshotClassName, "unexpected value for Spec.VolumeSnapshotClassName, Want: %s, Got: %s", *tc.vs.Spec.VolumeSnapshotClassName, *before.Spec.VolumeSnapshotClassName) assert.Nil(t, tc.vs.Status) }) diff --git a/pkg/test/fake_discovery_helper.go b/pkg/test/fake_discovery_helper.go index 79b3de7f2..89218adbf 100644 --- a/pkg/test/fake_discovery_helper.go +++ b/pkg/test/fake_discovery_helper.go @@ -158,7 +158,7 @@ func (di *FakeServerResourcesInterface) ServerPreferredResources() ([]*metav1.AP if di.ReturnError != nil { return di.ResourceList, di.ReturnError } - if di.FailedGroups == nil || len(di.FailedGroups) == 0 { + if len(di.FailedGroups) == 0 { return di.ResourceList, nil } return di.ResourceList, &discovery.ErrGroupDiscoveryFailed{Groups: di.FailedGroups} @@ -168,7 +168,7 @@ func (di *FakeServerResourcesInterface) ServerGroupsAndResources() ([]*metav1.AP if di.ReturnError != nil { return di.APIGroup, di.ResourceList, di.ReturnError } - if di.FailedGroups == nil || len(di.FailedGroups) == 0 { + if len(di.FailedGroups) == 0 { return di.APIGroup, di.ResourceList, nil } return di.APIGroup, di.ResourceList, &discovery.ErrGroupDiscoveryFailed{Groups: di.FailedGroups} diff --git a/pkg/util/kube/mocks.go b/pkg/util/kube/mocks.go index f6d7d049b..27ff9bc34 100644 --- a/pkg/util/kube/mocks.go +++ b/pkg/util/kube/mocks.go @@ -8,7 +8,8 @@ import ( ) // Client knows how to perform CRUD operations on Kubernetes objects. -// go:generate mockery --name=Client +// +//go:generate mockery --name=Client type Client interface { client.Reader client.Writer diff --git a/pkg/util/kube/pvc_pv.go b/pkg/util/kube/pvc_pv.go index 6d29c2e94..49eb91dbe 100644 --- a/pkg/util/kube/pvc_pv.go +++ b/pkg/util/kube/pvc_pv.go @@ -83,7 +83,7 @@ func WaitPVCBound(ctx context.Context, pvcGetter corev1client.CoreV1Interface, err := wait.PollUntilContextTimeout(ctx, waitInternal, timeout, true, func(ctx context.Context) (bool, error) { tmpPVC, err := pvcGetter.PersistentVolumeClaims(namespace).Get(ctx, pvc, metav1.GetOptions{}) if err != nil { - return false, errors.Wrapf(err, fmt.Sprintf("error to get pvc %s/%s", namespace, pvc)) + return false, errors.Wrapf(err, "error to get pvc %s/%s", namespace, pvc) } if tmpPVC.Spec.VolumeName == "" { @@ -318,7 +318,7 @@ func WaitPVBound(ctx context.Context, pvGetter corev1client.CoreV1Interface, pvN err := wait.PollUntilContextTimeout(ctx, waitInternal, timeout, true, func(ctx context.Context) (bool, error) { tmpPV, err := pvGetter.PersistentVolumes().Get(ctx, pvName, metav1.GetOptions{}) if err != nil { - return false, errors.Wrapf(err, fmt.Sprintf("failed to get pv %s", pvName)) + return false, errors.Wrapf(err, "failed to get pv %s", pvName) } if tmpPV.Spec.ClaimRef == nil { diff --git a/test/e2e/basic/backup-volume-info/csi_data_mover.go b/test/e2e/basic/backup-volume-info/csi_data_mover.go index de1ca5c42..43edb0ddb 100644 --- a/test/e2e/basic/backup-volume-info/csi_data_mover.go +++ b/test/e2e/basic/backup-volume-info/csi_data_mover.go @@ -58,7 +58,7 @@ func (c *CSIDataMoverVolumeInfo) Verify() error { Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.") fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0]) - Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true)) + Expect(volumeInfo).ToNot(BeEmpty()) Expect(volumeInfo[0].SnapshotDataMovementInfo).NotTo(BeNil()) return nil diff --git a/test/e2e/basic/backup-volume-info/csi_snapshot.go b/test/e2e/basic/backup-volume-info/csi_snapshot.go index ef476421c..5eddb4ea2 100644 --- a/test/e2e/basic/backup-volume-info/csi_snapshot.go +++ b/test/e2e/basic/backup-volume-info/csi_snapshot.go @@ -57,7 +57,7 @@ func (c *CSISnapshotVolumeInfo) Verify() error { Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.") fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0]) - Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true)) + Expect(volumeInfo).ToNot(BeEmpty()) Expect(volumeInfo[0].CSISnapshotInfo).NotTo(BeNil()) return nil diff --git a/test/e2e/basic/backup-volume-info/filesystem_upload.go b/test/e2e/basic/backup-volume-info/filesystem_upload.go index d58eee5ad..e6266c0c6 100644 --- a/test/e2e/basic/backup-volume-info/filesystem_upload.go +++ b/test/e2e/basic/backup-volume-info/filesystem_upload.go @@ -57,7 +57,7 @@ func (f *FilesystemUploadVolumeInfo) Verify() error { Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.") fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0]) - Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true)) + Expect(volumeInfo).ToNot(BeEmpty()) Expect(volumeInfo[0].PVBInfo).NotTo(BeNil()) return nil diff --git a/test/e2e/basic/backup-volume-info/native_snapshot.go b/test/e2e/basic/backup-volume-info/native_snapshot.go index b4200f85c..13a75d2e6 100644 --- a/test/e2e/basic/backup-volume-info/native_snapshot.go +++ b/test/e2e/basic/backup-volume-info/native_snapshot.go @@ -58,7 +58,7 @@ func (n *NativeSnapshotVolumeInfo) Verify() error { Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.") fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0]) - Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true)) + Expect(volumeInfo).ToNot(BeEmpty()) Expect(volumeInfo[0].NativeSnapshotInfo).NotTo(BeNil()) return nil diff --git a/test/e2e/basic/backup-volume-info/skipped_volumes.go b/test/e2e/basic/backup-volume-info/skipped_volumes.go index 0f1ccec0c..2fc801a5f 100644 --- a/test/e2e/basic/backup-volume-info/skipped_volumes.go +++ b/test/e2e/basic/backup-volume-info/skipped_volumes.go @@ -57,7 +57,7 @@ func (s *SkippedVolumeInfo) Verify() error { Expect(err).ShouldNot(HaveOccurred(), "Fail to get VolumeInfo metadata in the Backup Repository.") fmt.Printf("The VolumeInfo metadata content: %+v\n", *volumeInfo[0]) - Expect(len(volumeInfo) > 0).To(BeIdenticalTo(true)) + Expect(volumeInfo).ToNot(BeEmpty()) Expect(volumeInfo[0].Skipped).To(BeIdenticalTo(true)) return nil diff --git a/test/e2e/resource-filtering/exclude_resources.go b/test/e2e/resource-filtering/exclude_resources.go index 5c2f37e73..b8a7d2e73 100644 --- a/test/e2e/resource-filtering/exclude_resources.go +++ b/test/e2e/resource-filtering/exclude_resources.go @@ -111,7 +111,7 @@ func (e *ExcludeResources) Verify() error { } return errors.Wrap(err, fmt.Sprintf("failed to list secrets in namespace: %q", namespace)) } else if len(secretsList.Items) != 0 { - return errors.Errorf(fmt.Sprintf("Should no secrets found %s in namespace: %q", secretsList.Items[0].Name, namespace)) + return errors.Errorf("Should no secrets found %s in namespace: %q", secretsList.Items[0].Name, namespace) } //Check configmap @@ -119,7 +119,7 @@ func (e *ExcludeResources) Verify() error { if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list configmap in namespace: %q", namespace)) } else if len(configmapList.Items) == 0 { - return errors.Errorf(fmt.Sprintf("Should have configmap found in namespace: %q", namespace)) + return errors.Errorf("Should have configmap found in namespace: %q", namespace) } } return nil diff --git a/test/e2e/resource-filtering/include_resources.go b/test/e2e/resource-filtering/include_resources.go index 23199d2de..22d7e968b 100644 --- a/test/e2e/resource-filtering/include_resources.go +++ b/test/e2e/resource-filtering/include_resources.go @@ -107,7 +107,7 @@ func (i *IncludeResources) Verify() error { } return errors.Wrap(err, fmt.Sprintf("failed to list secrets in namespace: %q", namespace)) } else if len(secretsList.Items) != 0 { - return errors.Errorf(fmt.Sprintf("Should no secrets found %s in namespace: %q", secretsList.Items[0].Name, namespace)) + return errors.Errorf("Should no secrets found %s in namespace: %q", secretsList.Items[0].Name, namespace) } //Check configmap @@ -115,7 +115,7 @@ func (i *IncludeResources) Verify() error { if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list configmap in namespace: %q", namespace)) } else if len(configmapList.Items) == 0 { - return errors.Errorf(fmt.Sprintf("Should have configmap found in namespace: %q", namespace)) + return errors.Errorf("Should have configmap found in namespace: %q", namespace) } } return nil diff --git a/test/e2e/resource-filtering/label_selector.go b/test/e2e/resource-filtering/label_selector.go index 1d566b585..97e3d71ae 100644 --- a/test/e2e/resource-filtering/label_selector.go +++ b/test/e2e/resource-filtering/label_selector.go @@ -142,7 +142,7 @@ func (l *LabelSelector) Verify() error { if err != nil { return errors.Wrap(err, fmt.Sprintf("failed to list secrets in namespace: %q", namespace)) } else if len(secretsList.Items) == 0 { - return errors.Errorf(fmt.Sprintf("no secrets found in namespace: %q", namespace)) + return errors.Errorf("no secrets found in namespace: %q", namespace) } } else { //exclude if err == nil { diff --git a/test/util/k8s/common.go b/test/util/k8s/common.go index 95f685811..6ea424539 100644 --- a/test/util/k8s/common.go +++ b/test/util/k8s/common.go @@ -77,7 +77,7 @@ func WaitForPods(ctx context.Context, client TestClient, namespace string, pods return true, nil }) if err != nil { - return errors.Wrapf(err, fmt.Sprintf("Failed to wait for pods in namespace %s to start running", namespace)) + return errors.Wrapf(err, "Failed to wait for pods in namespace %s to start running", namespace) } return nil } diff --git a/test/util/kibishii/kibishii_utils.go b/test/util/kibishii/kibishii_utils.go index be503ff0b..e701856ad 100644 --- a/test/util/kibishii/kibishii_utils.go +++ b/test/util/kibishii/kibishii_utils.go @@ -333,7 +333,7 @@ func generateData(ctx context.Context, namespace string, kibishiiData *KibishiiD }) if err != nil { - return errors.Wrapf(err, fmt.Sprintf("Failed to wait generate data in namespace %s", namespace)) + return errors.Wrapf(err, "Failed to wait generate data in namespace %s", namespace) } return nil } @@ -363,7 +363,7 @@ func verifyData(ctx context.Context, namespace string, kibishiiData *KibishiiDat }) if err != nil { - return errors.Wrapf(err, fmt.Sprintf("Failed to verify kibishii data in namespace %s\n", namespace)) + return errors.Wrapf(err, "Failed to verify kibishii data in namespace %s\n", namespace) } fmt.Printf("Success to verify kibishii data in namespace %s\n", namespace) return nil @@ -430,7 +430,7 @@ func KibishiiVerifyAfterRestore(client TestClient, kibishiiNamespace string, one for _, pod := range KibishiiPodNameList { exist, err := FileExistInPV(oneHourTimeout, kibishiiNamespace, pod, "kibishii", "data", incrementalFileName) if err != nil { - return errors.Wrapf(err, fmt.Sprintf("fail to get file %s", incrementalFileName)) + return errors.Wrapf(err, "fail to get file %s", incrementalFileName) } if exist { diff --git a/test/util/providers/azure_utils.go b/test/util/providers/azure_utils.go index 86c439fb6..20cab54ba 100644 --- a/test/util/providers/azure_utils.go +++ b/test/util/providers/azure_utils.go @@ -168,7 +168,7 @@ func getStorageAccountKey(credentialsFile, accountName, subscriptionID, resource if err != nil { return "", errors.WithStack(err) } - if res.Keys == nil || len(res.Keys) == 0 { + if len(res.Keys) == 0 { return "", errors.New("No storage keys found") } diff --git a/test/util/providers/gcloud_utils.go b/test/util/providers/gcloud_utils.go index f653aa02a..99e60a61e 100644 --- a/test/util/providers/gcloud_utils.go +++ b/test/util/providers/gcloud_utils.go @@ -97,7 +97,7 @@ func (s GCSStorage) DeleteObjectsInBucket(cloudCredentialsFile, bslBucket, bslPr if strings.Contains(obj.Name, bslPrefix+backupObject+"/") { fmt.Printf("Delete item: %s\n", obj.Name) if err = bucket.Object(obj.Name).Delete(ctx); err != nil { - return errors.Wrapf(err, fmt.Sprintf("Fail to delete object %s in bucket %s", obj.Name, bslBucket)) + return errors.Wrapf(err, "Fail to delete object %s in bucket %s", obj.Name, bslBucket) } } } @@ -107,12 +107,12 @@ func (s GCSStorage) IsSnapshotExisted(cloudCredentialsFile, bslConfig, backupObj ctx := context.Background() data, err := os.ReadFile(cloudCredentialsFile) if err != nil { - return errors.Wrapf(err, fmt.Sprintf("Failed reading gcloud credential file %s", cloudCredentialsFile)) + return errors.Wrapf(err, "Failed reading gcloud credential file %s", cloudCredentialsFile) } creds, err := google.CredentialsFromJSON(ctx, data) if err != nil { - return errors.Wrapf(err, fmt.Sprintf("Failed getting credentials from JSON data %s", string(data))) + return errors.Wrapf(err, "Failed getting credentials from JSON data %s", string(data)) } computeService, err := compute.NewService(context.Background(), option.WithCredentialsFile(cloudCredentialsFile))