From 16b8233d61c1b5e19559f976c33e1a19a9bd2b79 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Mon, 25 Mar 2024 21:27:29 +0000 Subject: [PATCH] lint(ginkgolinter): expect (not)to HaveOccurred Signed-off-by: Matthieu MOREL --- internal/hook/hook_tracker_test.go | 1 - internal/hook/item_hook_handler_test.go | 2 -- internal/hook/wait_exec_hook_handler_test.go | 2 -- .../resource_modifiers_test.go | 1 - .../resourcepolicies/volume_resources_test.go | 3 --- internal/storage/storagelocation_test.go | 4 ++-- internal/velero/images_test.go | 1 - pkg/backup/item_collector_test.go | 1 - pkg/backup/remap_crd_version_action_test.go | 2 -- pkg/backup/service_account_action_test.go | 2 -- pkg/buildinfo/buildinfo_test.go | 1 - pkg/client/config_test.go | 1 - pkg/cmd/cli/backup/create_test.go | 2 -- pkg/cmd/cli/backuplocation/delete_test.go | 2 -- pkg/cmd/cli/restore/create_test.go | 1 - pkg/cmd/util/flag/map_test.go | 1 - .../output/backup_structured_describer_test.go | 1 - pkg/controller/backup_controller_test.go | 2 -- .../backup_deletion_controller_test.go | 5 ----- .../backup_repository_controller_test.go | 1 - .../backup_storage_location_controller_test.go | 8 ++++---- pkg/controller/backup_sync_controller_test.go | 4 ++-- .../data_download_controller_test.go | 4 +--- pkg/controller/data_upload_controller_test.go | 3 +-- .../download_request_controller_test.go | 14 +++++++------- .../pod_volume_backup_controller_test.go | 18 +++++++++--------- pkg/controller/restore_controller_test.go | 2 -- .../restore_finalizer_controller_test.go | 3 --- .../server_status_request_controller_test.go | 6 +++--- pkg/exposer/csi_snapshot_test.go | 1 - pkg/persistence/object_store_test.go | 1 - .../clientmgmt/process/client_builder_test.go | 1 - pkg/podvolume/backupper_test.go | 4 +--- pkg/podvolume/restorer_test.go | 1 - pkg/podvolume/util_test.go | 1 - pkg/restic/command_factory_test.go | 1 - pkg/restore/merge_service_account_test.go | 1 - pkg/restore/restore_test.go | 3 --- pkg/restore/service_action_test.go | 1 - pkg/uploader/kopia/snapshot_test.go | 1 - pkg/uploader/provider/kopia_test.go | 2 +- pkg/uploader/provider/provider_test.go | 1 - pkg/uploader/provider/restic_test.go | 1 - pkg/util/azure/credential_test.go | 1 - pkg/util/collections/includes_excludes_test.go | 1 - pkg/util/csi/util_test.go | 1 - pkg/util/kube/utils_test.go | 1 - 47 files changed, 31 insertions(+), 91 deletions(-) diff --git a/internal/hook/hook_tracker_test.go b/internal/hook/hook_tracker_test.go index 9e6ca95d33..dde7b85210 100644 --- a/internal/hook/hook_tracker_test.go +++ b/internal/hook/hook_tracker_test.go @@ -67,7 +67,6 @@ func TestHookTracker_Record(t *testing.T) { err = tracker.Record("ns2", "pod2", "container1", HookSourceAnnotation, "h1", PhasePre, true) assert.NotNil(t, err) - } func TestHookTracker_Stat(t *testing.T) { diff --git a/internal/hook/item_hook_handler_test.go b/internal/hook/item_hook_handler_test.go index f8efb5f089..a972189433 100644 --- a/internal/hook/item_hook_handler_test.go +++ b/internal/hook/item_hook_handler_test.go @@ -2351,14 +2351,12 @@ func TestBackupHookTracker(t *testing.T) { } } h.HandleHooks(velerotest.NewLogger(), groupResource, pod.item, pod.hooks, test.phase, hookTracker) - } actualAtemptted, actualFailed := hookTracker.Stat() assert.Equal(t, test.expectedHookAttempted, actualAtemptted) assert.Equal(t, test.expectedHookFailed, actualFailed) }) } - } func TestRestoreHookTrackerAdd(t *testing.T) { diff --git a/internal/hook/wait_exec_hook_handler_test.go b/internal/hook/wait_exec_hook_handler_test.go index 3f23542744..2f8d7ad7ac 100644 --- a/internal/hook/wait_exec_hook_handler_test.go +++ b/internal/hook/wait_exec_hook_handler_test.go @@ -710,7 +710,6 @@ func TestWaitExecHandleHooks(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - source := fcache.NewFakeControllerSource() go func() { // This is the state of the pod that will be seen by the AddFunc handler. @@ -1251,7 +1250,6 @@ func TestRestoreHookTrackerUpdate(t *testing.T) { for _, test := range tests1 { t.Run(test.name, func(t *testing.T) { - source := fcache.NewFakeControllerSource() go func() { // This is the state of the pod that will be seen by the AddFunc handler. diff --git a/internal/resourcemodifiers/resource_modifiers_test.go b/internal/resourcemodifiers/resource_modifiers_test.go index 648d827be9..8b4384ef1e 100644 --- a/internal/resourcemodifiers/resource_modifiers_test.go +++ b/internal/resourcemodifiers/resource_modifiers_test.go @@ -428,7 +428,6 @@ func TestGetResourceModifiersFromConfig(t *testing.T) { } func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) { - pvcStandardSc := &unstructured.Unstructured{ Object: map[string]interface{}{ "apiVersion": "v1", diff --git a/internal/resourcepolicies/volume_resources_test.go b/internal/resourcepolicies/volume_resources_test.go index c73bb692d8..f852baff3b 100644 --- a/internal/resourcepolicies/volume_resources_test.go +++ b/internal/resourcepolicies/volume_resources_test.go @@ -86,7 +86,6 @@ func TestCapacityIsInRange(t *testing.T) { actual := test.capacity.isInRange(test.quantity) assert.Equal(t, test.isInRange, actual) - }) } } @@ -141,7 +140,6 @@ func TestStorageClassConditionMatch(t *testing.T) { } func TestNFSConditionMatch(t *testing.T) { - tests := []struct { name string condition *nfsCondition @@ -196,7 +194,6 @@ func TestNFSConditionMatch(t *testing.T) { } func TestCSIConditionMatch(t *testing.T) { - tests := []struct { name string condition *csiCondition diff --git a/internal/storage/storagelocation_test.go b/internal/storage/storagelocation_test.go index 650e7338ab..285c5db608 100644 --- a/internal/storage/storagelocation_test.go +++ b/internal/storage/storagelocation_test.go @@ -166,10 +166,10 @@ func TestListBackupStorageLocations(t *testing.T) { client := fake.NewClientBuilder().WithScheme(util.VeleroScheme).WithRuntimeObjects(tt.backupLocations).Build() if tt.expectError { _, err := ListBackupStorageLocations(context.Background(), client, "ns-1") - g.Expect(err).NotTo(BeNil()) + g.Expect(err).To(HaveOccurred()) } else { _, err := ListBackupStorageLocations(context.Background(), client, "ns-1") - g.Expect(err).To(BeNil()) + g.Expect(err).ToNot(HaveOccurred()) } }) } diff --git a/internal/velero/images_test.go b/internal/velero/images_test.go index 7d6bdf8cd9..ad73452930 100644 --- a/internal/velero/images_test.go +++ b/internal/velero/images_test.go @@ -128,7 +128,6 @@ func testDefaultImage(t *testing.T, defaultImageFn func() string, imageName stri assert.Equal(t, tc.want, defaultImageFn()) }) } - } func TestDefaultVeleroImage(t *testing.T) { diff --git a/pkg/backup/item_collector_test.go b/pkg/backup/item_collector_test.go index f44743dfb5..467ce96a75 100644 --- a/pkg/backup/item_collector_test.go +++ b/pkg/backup/item_collector_test.go @@ -76,5 +76,4 @@ func TestSortOrderedResource(t *testing.T) { } sortedPvResources := sortResourcesByOrder(log, pvResources, pvOrder) assert.Equal(t, sortedPvResources, expectedPvResources) - } diff --git a/pkg/backup/remap_crd_version_action_test.go b/pkg/backup/remap_crd_version_action_test.go index bbcedd32b9..b50f82de4b 100644 --- a/pkg/backup/remap_crd_version_action_test.go +++ b/pkg/backup/remap_crd_version_action_test.go @@ -136,7 +136,6 @@ func TestRemapCRDVersionAction(t *testing.T) { // set it back to the default one a.discoveryHelper = fakeDiscoveryHelper() }) - } // TestRemapCRDVersionActionData tests the RemapCRDVersionAction plugin against actual CRD to confirm that the v1beta1 version is returned when the v1 version is passed in to the plugin. @@ -217,7 +216,6 @@ func TestRemapCRDVersionActionData(t *testing.T) { betaClient.Delete(context.TODO(), crd.Name, metav1.DeleteOptions{}) }) } - } func fakeDiscoveryHelper() velerodiscovery.Helper { diff --git a/pkg/backup/service_account_action_test.go b/pkg/backup/service_account_action_test.go index b17b9748cb..9bb813d6d5 100644 --- a/pkg/backup/service_account_action_test.go +++ b/pkg/backup/service_account_action_test.go @@ -400,7 +400,6 @@ func TestServiceAccountActionExecute(t *testing.T) { assert.Equal(t, test.expectedAdditionalItems, additional) }) } - } func TestServiceAccountActionExecuteOnBeta1(t *testing.T) { @@ -608,5 +607,4 @@ func TestServiceAccountActionExecuteOnBeta1(t *testing.T) { assert.Equal(t, test.expectedAdditionalItems, additional) }) } - } diff --git a/pkg/buildinfo/buildinfo_test.go b/pkg/buildinfo/buildinfo_test.go index 40631525a1..be12bdcab6 100644 --- a/pkg/buildinfo/buildinfo_test.go +++ b/pkg/buildinfo/buildinfo_test.go @@ -49,5 +49,4 @@ func TestFormattedGitSHA(t *testing.T) { assert.Equal(t, FormattedGitSHA(), test.expected) }) } - } diff --git a/pkg/client/config_test.go b/pkg/client/config_test.go index 938345b5ae..8467c854cd 100644 --- a/pkg/client/config_test.go +++ b/pkg/client/config_test.go @@ -48,7 +48,6 @@ func removeConfigfileName() error { return nil } func TestConfigOperations(t *testing.T) { - preHomeEnv := "" prevEnv := os.Environ() for _, entry := range prevEnv { diff --git a/pkg/cmd/cli/backup/create_test.go b/pkg/cmd/cli/backup/create_test.go index e115bbd199..084d67becb 100644 --- a/pkg/cmd/cli/backup/create_test.go +++ b/pkg/cmd/cli/backup/create_test.go @@ -148,7 +148,6 @@ func TestCreateOptions_OrderedResources(t *testing.T) { "persistentvolumes": "pv1,pv2", } assert.Equal(t, orderedResources, expectedMixedResources) - } func TestCreateCommand(t *testing.T) { @@ -156,7 +155,6 @@ func TestCreateCommand(t *testing.T) { args := []string{name} t.Run("create a backup create command with full options except fromSchedule and wait, then run by create option", func(t *testing.T) { - // create a factory f := &factorymocks.Factory{} diff --git a/pkg/cmd/cli/backuplocation/delete_test.go b/pkg/cmd/cli/backuplocation/delete_test.go index 9736c9883a..24c85def6f 100644 --- a/pkg/cmd/cli/backuplocation/delete_test.go +++ b/pkg/cmd/cli/backuplocation/delete_test.go @@ -35,7 +35,6 @@ import ( ) func TestNewDeleteCommand(t *testing.T) { - // create a factory f := &factorymocks.Factory{} kbclient := velerotest.NewFakeControllerRuntimeClient(t) @@ -75,7 +74,6 @@ func TestNewDeleteCommand(t *testing.T) { return } t.Fatalf("process ran with err %v, want backups by get()", err) - } func TestDeleteFunctions(t *testing.T) { //t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) { diff --git a/pkg/cmd/cli/restore/create_test.go b/pkg/cmd/cli/restore/create_test.go index 6a68018c47..4fbe7f3723 100644 --- a/pkg/cmd/cli/restore/create_test.go +++ b/pkg/cmd/cli/restore/create_test.go @@ -59,7 +59,6 @@ func TestCreateCommand(t *testing.T) { args := []string{name} t.Run("create a backup create command with full options except fromSchedule and wait, then run by create option", func(t *testing.T) { - // create a factory f := &factorymocks.Factory{} diff --git a/pkg/cmd/util/flag/map_test.go b/pkg/cmd/util/flag/map_test.go index c0a1dee7ef..70a71fbb18 100644 --- a/pkg/cmd/util/flag/map_test.go +++ b/pkg/cmd/util/flag/map_test.go @@ -71,7 +71,6 @@ func TestSetOfMap(t *testing.T) { assert.EqualValues(t, c.expected, m.Data()) }) } - } func TestStringOfMap(t *testing.T) { diff --git a/pkg/cmd/util/output/backup_structured_describer_test.go b/pkg/cmd/util/output/backup_structured_describer_test.go index afddec0a2a..58a141cd9c 100644 --- a/pkg/cmd/util/output/backup_structured_describer_test.go +++ b/pkg/cmd/util/output/backup_structured_describer_test.go @@ -618,5 +618,4 @@ func TestDescribeDeleteBackupRequestsInSF(t *testing.T) { assert.True(tt, reflect.DeepEqual(sd.output, tc.expect)) }) } - } diff --git a/pkg/controller/backup_controller_test.go b/pkg/controller/backup_controller_test.go index 7dd3922996..37caf839e4 100644 --- a/pkg/controller/backup_controller_test.go +++ b/pkg/controller/backup_controller_test.go @@ -435,7 +435,6 @@ func TestDefaultBackupTTL(t *testing.T) { ) t.Run(test.name, func(t *testing.T) { - apiServer := velerotest.NewAPIServer(t) discoveryHelper, err := discovery.NewHelper(apiServer.DiscoveryClient, logger) require.NoError(t, err) @@ -1735,6 +1734,5 @@ func TestPatchResourceWorksWithStatus(t *testing.T) { t.Error(cmp.Diff(fromCluster, tt.args.updated)) } }) - } } diff --git a/pkg/controller/backup_deletion_controller_test.go b/pkg/controller/backup_deletion_controller_test.go index 6f44d75cb6..f2777ecd85 100644 --- a/pkg/controller/backup_deletion_controller_test.go +++ b/pkg/controller/backup_deletion_controller_test.go @@ -75,7 +75,6 @@ func defaultTestDbr() *velerov1api.DeleteBackupRequest { } func setupBackupDeletionControllerTest(t *testing.T, req *velerov1api.DeleteBackupRequest, objects ...runtime.Object) *backupDeletionControllerTestData { - var ( fakeClient = velerotest.NewFakeControllerRuntimeClient(t, append(objects, req)...) volumeSnapshotter = &velerotest.FakeVolumeSnapshotter{SnapshotsTaken: sets.NewString()} @@ -215,7 +214,6 @@ func TestBackupDeletionControllerReconcile(t *testing.T) { }) t.Run("unable to find backup", func(t *testing.T) { - td := setupBackupDeletionControllerTest(t, defaultTestDbr()) _, err := td.controller.Reconcile(context.TODO(), td.req) @@ -261,7 +259,6 @@ func TestBackupDeletionControllerReconcile(t *testing.T) { assert.Equal(t, "cannot delete backup because backup storage location default is currently in read-only mode", res.Status.Errors[0]) }) t.Run("full delete, no errors", func(t *testing.T) { - input := defaultTestDbr() // Clear out resource labels to make sure the controller adds them and does not @@ -668,7 +665,6 @@ func TestBackupDeletionControllerReconcile(t *testing.T) { err = td.fakeClient.Get(ctx, td.req.NamespacedName, res) assert.True(t, apierrors.IsNotFound(err), "Expected not found error, but actual value of error: %v", err) td.backupStore.AssertNotCalled(t, "DeleteBackup", mock.Anything) - }) t.Run("Expired request will not be deleted if the status is not processed", func(t *testing.T) { @@ -690,7 +686,6 @@ func TestBackupDeletionControllerReconcile(t *testing.T) { assert.Equal(t, "Processed", string(res.Status.Phase)) assert.Equal(t, 1, len(res.Status.Errors)) assert.Equal(t, "backup not found", res.Status.Errors[0]) - }) } diff --git a/pkg/controller/backup_repository_controller_test.go b/pkg/controller/backup_repository_controller_test.go index 22c64b45e8..70dfd1e799 100644 --- a/pkg/controller/backup_repository_controller_test.go +++ b/pkg/controller/backup_repository_controller_test.go @@ -57,7 +57,6 @@ func mockBackupRepositoryCR() *velerov1api.BackupRepository { MaintenanceFrequency: metav1.Duration{Duration: testMaintenanceFrequency}, }, } - } func TestPatchBackupRepository(t *testing.T) { diff --git a/pkg/controller/backup_storage_location_controller_test.go b/pkg/controller/backup_storage_location_controller_test.go index 5742c36887..f63305c9e1 100644 --- a/pkg/controller/backup_storage_location_controller_test.go +++ b/pkg/controller/backup_storage_location_controller_test.go @@ -100,12 +100,12 @@ var _ = Describe("Backup Storage Location Reconciler", func() { NamespacedName: types.NamespacedName{Namespace: location.Namespace, Name: location.Name}, }) Expect(actualResult).To(BeEquivalentTo(ctrl.Result{})) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) key := client.ObjectKey{Name: location.Name, Namespace: location.Namespace} instance := &velerov1api.BackupStorageLocation{} err = r.client.Get(ctx, key, instance) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) Expect(instance.Spec.Default).To(BeIdenticalTo(tests[i].expectedIsDefault)) Expect(instance.Status.Phase).To(BeIdenticalTo(tests[i].expectedPhase)) } @@ -165,12 +165,12 @@ var _ = Describe("Backup Storage Location Reconciler", func() { NamespacedName: types.NamespacedName{Namespace: location.Namespace, Name: location.Name}, }) Expect(actualResult).To(BeEquivalentTo(ctrl.Result{})) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) key := client.ObjectKey{Name: location.Name, Namespace: location.Namespace} instance := &velerov1api.BackupStorageLocation{} err = r.client.Get(ctx, key, instance) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) Expect(instance.Spec.Default).To(BeIdenticalTo(tests[i].expectedIsDefault)) } }) diff --git a/pkg/controller/backup_sync_controller_test.go b/pkg/controller/backup_sync_controller_test.go index 424eb15227..35031f44ae 100644 --- a/pkg/controller/backup_sync_controller_test.go +++ b/pkg/controller/backup_sync_controller_test.go @@ -451,7 +451,7 @@ var _ = Describe("Backup Sync Reconciler", func() { }) Expect(actualResult).To(BeEquivalentTo(ctrl.Result{})) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) // process the cloud backups for _, cloudBackupData := range test.cloudBackups { @@ -467,7 +467,7 @@ var _ = Describe("Backup Sync Reconciler", func() { cloudBackupData.backup.Status.Expiration.After(fakeClock.Now())) { Expect(apierrors.IsNotFound(err)).To(BeTrue()) } else { - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) // did this cloud backup already exist in the cluster? var existing *velerov1api.Backup diff --git a/pkg/controller/data_download_controller_test.go b/pkg/controller/data_download_controller_test.go index e65b2afff1..b0abc7a395 100644 --- a/pkg/controller/data_download_controller_test.go +++ b/pkg/controller/data_download_controller_test.go @@ -526,7 +526,6 @@ func TestOnDataDownloadCompleted(t *testing.T) { ep := exposermockes.NewGenericRestoreExposer(t) if test.rebindVolumeErr { ep.On("RebindVolume", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(errors.New("Error to rebind volume")) - } else { ep.On("RebindVolume", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) } @@ -813,7 +812,6 @@ func TestTryCancelDataDownload(t *testing.T) { } func TestUpdateDataDownloadWithRetry(t *testing.T) { - namespacedName := types.NamespacedName{ Name: dataDownloadName, Namespace: "velero", @@ -1026,7 +1024,7 @@ func TestAttemptDataDownloadResume(t *testing.T) { } else { assert.NoError(t, err) - // Verify DataDownload marked as Cancelled + // Verify DataDownload marked as Canceled for _, duName := range test.cancelledDataDownloads { dataUpload := &velerov2alpha1api.DataDownload{} err := r.client.Get(context.Background(), types.NamespacedName{Namespace: "velero", Name: duName}, dataUpload) diff --git a/pkg/controller/data_upload_controller_test.go b/pkg/controller/data_upload_controller_test.go index bf9a5674d1..eb440c7686 100644 --- a/pkg/controller/data_upload_controller_test.go +++ b/pkg/controller/data_upload_controller_test.go @@ -885,7 +885,6 @@ func TestTryCancelDataUpload(t *testing.T) { } func TestUpdateDataUploadWithRetry(t *testing.T) { - namespacedName := types.NamespacedName{ Name: dataUploadName, Namespace: "velero", @@ -1097,7 +1096,7 @@ func TestAttemptDataUploadResume(t *testing.T) { } else { assert.NoError(t, err) - // Verify DataUploads marked as Cancelled + // Verify DataUploads marked as Canceled for _, duName := range test.cancelledDataUploads { dataUpload := &velerov2alpha1api.DataUpload{} err := r.client.Get(context.Background(), types.NamespacedName{Namespace: "velero", Name: duName}, dataUpload) diff --git a/pkg/controller/download_request_controller_test.go b/pkg/controller/download_request_controller_test.go index 1847719913..3e675f34be 100644 --- a/pkg/controller/download_request_controller_test.go +++ b/pkg/controller/download_request_controller_test.go @@ -62,7 +62,7 @@ var _ = Describe("Download Request Reconciler", func() { // now will be used to set the fake clock's time; capture // it here so it can be referenced in the test case defs. now, err := time.Parse(time.RFC1123, time.RFC1123) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) now = now.Local() rClock := testclocks.NewFakeClock(now) @@ -86,22 +86,22 @@ var _ = Describe("Download Request Reconciler", func() { fakeClient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build() err = fakeClient.Create(context.TODO(), test.downloadRequest) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) if test.backup != nil { err := fakeClient.Create(context.TODO(), test.backup) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) } if test.backupLocation != nil { err := fakeClient.Create(context.TODO(), test.backupLocation) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) backupStores[test.backupLocation.Name] = &persistencemocks.BackupStore{} } if test.restore != nil { err := fakeClient.Create(context.TODO(), test.restore) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) } // Setup reconciler @@ -129,7 +129,7 @@ var _ = Describe("Download Request Reconciler", func() { Expect(actualResult).To(BeEquivalentTo(test.expectedRequeue)) if test.expectedReconcileErr == "" { - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) } else { Expect(err.Error()).To(Equal(test.expectedReconcileErr)) } @@ -146,7 +146,7 @@ var _ = Describe("Download Request Reconciler", func() { } else { Expect(instance.Status).ToNot(Equal(test.downloadRequest.Status)) } - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) } if test.expectGetsURL { diff --git a/pkg/controller/pod_volume_backup_controller_test.go b/pkg/controller/pod_volume_backup_controller_test.go index c3685ff216..3968967bcb 100644 --- a/pkg/controller/pod_volume_backup_controller_test.go +++ b/pkg/controller/pod_volume_backup_controller_test.go @@ -141,7 +141,7 @@ var _ = Describe("PodVolumeBackup Reconciler", func() { // `now` will be used to set the fake clock's time; capture // it here so it can be referenced in the test case defs. now, err := time.Parse(time.RFC1123, time.RFC1123) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) now = now.Local() DescribeTable("a pod volume backup", @@ -150,21 +150,21 @@ var _ = Describe("PodVolumeBackup Reconciler", func() { fakeClient := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build() err = fakeClient.Create(ctx, test.pvb) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) err = fakeClient.Create(ctx, test.pod) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) err = fakeClient.Create(ctx, test.bsl) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) err = fakeClient.Create(ctx, test.backupRepo) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) fakeFS := velerotest.NewFakeFileSystem() pathGlob := fmt.Sprintf("/host_pods/%s/volumes/*/%s", "", "pvb-1-volume") _, err = fakeFS.Create(pathGlob) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) credentialFileStore, err := credentials.NewNamespacedFileStore( fakeClient, @@ -173,7 +173,7 @@ var _ = Describe("PodVolumeBackup Reconciler", func() { fakeFS, ) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) if test.dataMgr == nil { test.dataMgr = datapath.NewManager(1) @@ -208,7 +208,7 @@ var _ = Describe("PodVolumeBackup Reconciler", func() { }) Expect(actualResult).To(BeEquivalentTo(test.expectedRequeue)) if test.expectedErrMsg == "" { - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) } else { Expect(err.Error()).To(BeEquivalentTo(test.expectedErrMsg)) } @@ -222,7 +222,7 @@ var _ = Describe("PodVolumeBackup Reconciler", func() { if test.expected == nil { Expect(apierrors.IsNotFound(err)).To(BeTrue()) } else { - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) Eventually(pvb.Status.Phase).Should(Equal(test.expected.Status.Phase)) } diff --git a/pkg/controller/restore_controller_test.go b/pkg/controller/restore_controller_test.go index 65df4af57d..74fdbcb99f 100644 --- a/pkg/controller/restore_controller_test.go +++ b/pkg/controller/restore_controller_test.go @@ -53,7 +53,6 @@ import ( ) func TestFetchBackupInfo(t *testing.T) { - tests := []struct { name string backupName string @@ -206,7 +205,6 @@ func TestProcessQueueItemSkips(t *testing.T) { } func TestRestoreReconcile(t *testing.T) { - defaultStorageLocation := builder.ForBackupStorageLocation("velero", "default").Provider("myCloud").Bucket("bucket").Result() now, err := time.Parse(time.RFC1123Z, time.RFC1123Z) diff --git a/pkg/controller/restore_finalizer_controller_test.go b/pkg/controller/restore_finalizer_controller_test.go index 3a17bf637c..8e0d2f54b0 100644 --- a/pkg/controller/restore_finalizer_controller_test.go +++ b/pkg/controller/restore_finalizer_controller_test.go @@ -178,7 +178,6 @@ func TestRestoreFinalizerReconcile(t *testing.T) { } }) } - } func TestUpdateResult(t *testing.T) { @@ -453,7 +452,6 @@ func TestPatchDynamicPVWithVolumeInfo(t *testing.T) { assert.Equal(t, expectedPVInfo.ReclaimPolicy, string(pv.Spec.PersistentVolumeReclaimPolicy)) assert.Equal(t, expectedPVInfo.Labels, pv.Labels) } - } } @@ -489,5 +487,4 @@ func TestGetRestoredPVCFromRestoredResourceList(t *testing.T) { } actual = getRestoredPVCFromRestoredResourceList(restoredResourceList) assert.Equal(t, expected, actual) - } diff --git a/pkg/controller/server_status_request_controller_test.go b/pkg/controller/server_status_request_controller_test.go index d92eb0d56e..6111859f3a 100644 --- a/pkg/controller/server_status_request_controller_test.go +++ b/pkg/controller/server_status_request_controller_test.go @@ -55,7 +55,7 @@ var _ = Describe("Server Status Request Reconciler", func() { // `now` will be used to set the fake clock's time; capture // it here so it can be referenced in the test case defs. now, err := time.Parse(time.RFC1123, time.RFC1123) - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) now = now.Local() DescribeTable("a Server Status request", @@ -79,7 +79,7 @@ var _ = Describe("Server Status Request Reconciler", func() { Expect(actualResult).To(BeEquivalentTo(test.expectedRequeue)) if test.expectedErrMsg == "" { - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) } else { Expect(err.Error()).To(BeEquivalentTo(test.expectedErrMsg)) return @@ -92,7 +92,7 @@ var _ = Describe("Server Status Request Reconciler", func() { if test.expected == nil { Expect(apierrors.IsNotFound(err)).To(BeTrue()) } else { - Expect(err).To(BeNil()) + Expect(err).ToNot(HaveOccurred()) Eventually(instance.Status.Phase == test.expected.Status.Phase, timeout).Should(BeTrue()) } }, diff --git a/pkg/exposer/csi_snapshot_test.go b/pkg/exposer/csi_snapshot_test.go index fe75026372..85e8e96da1 100644 --- a/pkg/exposer/csi_snapshot_test.go +++ b/pkg/exposer/csi_snapshot_test.go @@ -440,7 +440,6 @@ func TestExpose(t *testing.T) { } else { assert.EqualError(t, err, test.err) } - }) } } diff --git a/pkg/persistence/object_store_test.go b/pkg/persistence/object_store_test.go index de3da29f1a..a63d31825c 100644 --- a/pkg/persistence/object_store_test.go +++ b/pkg/persistence/object_store_test.go @@ -1142,7 +1142,6 @@ func TestGetBackupVolumeInfos(t *testing.T) { if len(tc.expectedResult) > 0 { require.Equal(t, tc.expectedResult, result) } - }) } } diff --git a/pkg/plugin/clientmgmt/process/client_builder_test.go b/pkg/plugin/clientmgmt/process/client_builder_test.go index d822d43cbd..a8bf3ad46e 100644 --- a/pkg/plugin/clientmgmt/process/client_builder_test.go +++ b/pkg/plugin/clientmgmt/process/client_builder_test.go @@ -51,7 +51,6 @@ func TestNewClientBuilder(t *testing.T) { assert.Equal(t, []string{"run-plugins", "--log-level", "info", "--features", "feature1,feature2"}, cb.commandArgs) // Clear the features list in case other tests run in the same process. features.NewFeatureFlagSet() - } func TestClientConfig(t *testing.T) { diff --git a/pkg/podvolume/backupper_test.go b/pkg/podvolume/backupper_test.go index e08b772dd9..46c6e8b5bd 100644 --- a/pkg/podvolume/backupper_test.go +++ b/pkg/podvolume/backupper_test.go @@ -197,7 +197,6 @@ func Test_backupper_BackupPodVolumes_log_test(t *testing.T) { b.BackupPodVolumes(tt.args.backup, tt.args.pod, tt.args.volumesToBackup, tt.args.resPolicies, log) fmt.Println(logOutput.String()) assert.Contains(t, logOutput.String(), tt.wantLog) - }) } } @@ -495,7 +494,7 @@ func TestBackupPodVolumes(t *testing.T) { bsl: "fake-bsl", }, { - name: "context cancelled", + name: "context canceled", ctx: ctxWithCancel, volumes: []string{ "fake-volume-1", @@ -616,7 +615,6 @@ func TestBackupPodVolumes(t *testing.T) { for _, pvb := range test.retPVBs { bp.(*backupper).results[resultsKey(test.sourcePod.Namespace, test.sourcePod.Name)] <- pvb } - } }() diff --git a/pkg/podvolume/restorer_test.go b/pkg/podvolume/restorer_test.go index f630b0fd5f..efccc3ebc1 100644 --- a/pkg/podvolume/restorer_test.go +++ b/pkg/podvolume/restorer_test.go @@ -409,7 +409,6 @@ func TestRestorePodVolumes(t *testing.T) { for _, pvr := range test.retPVRs { rs.(*restorer).results[resultsKey(test.restoredPod.Namespace, test.restoredPod.Name)] <- pvr } - } }() diff --git a/pkg/podvolume/util_test.go b/pkg/podvolume/util_test.go index 79e68450cf..395b45a3fc 100644 --- a/pkg/podvolume/util_test.go +++ b/pkg/podvolume/util_test.go @@ -298,6 +298,5 @@ func TestVolumeHasNonRestorableSource(t *testing.T) { actual := volumeHasNonRestorableSource(tc.volumeName, tc.podVolumes) assert.Equal(t, tc.expected, actual) }) - } } diff --git a/pkg/restic/command_factory_test.go b/pkg/restic/command_factory_test.go index c0a627ad1f..75f20d47a5 100644 --- a/pkg/restic/command_factory_test.go +++ b/pkg/restic/command_factory_test.go @@ -89,7 +89,6 @@ func TestGetSnapshotCommand(t *testing.T) { assert.Equal(t, expectedFlags, actualFlags) assert.Equal(t, expectedTags, actualTags) - } func TestInitCommand(t *testing.T) { diff --git a/pkg/restore/merge_service_account_test.go b/pkg/restore/merge_service_account_test.go index e58c423744..4322ae0033 100644 --- a/pkg/restore/merge_service_account_test.go +++ b/pkg/restore/merge_service_account_test.go @@ -361,7 +361,6 @@ func TestMergeMaps(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - result := mergeMaps(tc.destination, tc.source) assert.Equal(t, tc.expected, result) diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index ee735386db..dd91382371 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -1859,7 +1859,6 @@ func TestRestoreWithAsyncOperations(t *testing.T) { UpdatedItem: obj, OperationID: obj.GetName() + "-1", }, nil - }, progressFunc: func(operationID string, restore *velerov1api.Restore) (velero.OperationProgress, error) { return velero.OperationProgress{ @@ -1881,7 +1880,6 @@ func TestRestoreWithAsyncOperations(t *testing.T) { UpdatedItem: obj, OperationID: obj.GetName() + "-1", }, nil - }, progressFunc: func(operationID string, restore *velerov1api.Restore) (velero.OperationProgress, error) { return velero.OperationProgress{ @@ -1902,7 +1900,6 @@ func TestRestoreWithAsyncOperations(t *testing.T) { return &velero.RestoreItemActionExecuteOutput{ UpdatedItem: obj, }, nil - }, } diff --git a/pkg/restore/service_action_test.go b/pkg/restore/service_action_test.go index be722fa2a0..16115e9202 100644 --- a/pkg/restore/service_action_test.go +++ b/pkg/restore/service_action_test.go @@ -65,7 +65,6 @@ func svcJSONFromUnstructured(ports ...map[string]interface{}) string { } func TestServiceActionExecute(t *testing.T) { - tests := []struct { name string obj corev1api.Service diff --git a/pkg/uploader/kopia/snapshot_test.go b/pkg/uploader/kopia/snapshot_test.go index 3021389fba..86c4e69714 100644 --- a/pkg/uploader/kopia/snapshot_test.go +++ b/pkg/uploader/kopia/snapshot_test.go @@ -79,7 +79,6 @@ func MockFuncs(s *snapshotMockes, args []mockArgs) { } func TestSnapshotSource(t *testing.T) { - ctx := context.TODO() sourceInfo := snapshot.SourceInfo{ UserName: "testUserName", diff --git a/pkg/uploader/provider/kopia_test.go b/pkg/uploader/provider/kopia_test.go index f1f16fb926..f6316c965a 100644 --- a/pkg/uploader/provider/kopia_test.go +++ b/pkg/uploader/provider/kopia_test.go @@ -228,7 +228,7 @@ func TestCheckContext(t *testing.T) { kp.CheckContext(ctx, tc.finishChan, tc.restoreChan, tc.uploader) if tc.expectCancel && tc.uploader != nil { - t.Error("Expected the uploader to be cancelled") + t.Error("Expected the uploader to be canceled") } if tc.expectBackup && tc.uploader == nil && len(tc.restoreChan) > 0 { diff --git a/pkg/uploader/provider/provider_test.go b/pkg/uploader/provider/provider_test.go index e04ff78b83..1d90c51f19 100644 --- a/pkg/uploader/provider/provider_test.go +++ b/pkg/uploader/provider/provider_test.go @@ -85,7 +85,6 @@ func TestNewUploaderProvider(t *testing.T) { mockFileGetter := &mocks.FileStore{} mockFileGetter.On("Path", &v1.SecretKeySelector{}).Return("", nil) credGetter.FromFile = mockFileGetter - } _, err := NewUploaderProvider(ctx, client, testCase.UploaderType, testCase.RequestorType, repoIdentifier, bsl, backupRepo, credGetter, repoKeySelector, log) if testCase.ExpectedError == "" { diff --git a/pkg/uploader/provider/restic_test.go b/pkg/uploader/provider/restic_test.go index c653ee1b51..7e828f948b 100644 --- a/pkg/uploader/provider/restic_test.go +++ b/pkg/uploader/provider/restic_test.go @@ -232,7 +232,6 @@ func TestResticRunRestore(t *testing.T) { require.Equal(t, true, tc.errorHandleFunc(err)) }) } - } func TestClose(t *testing.T) { diff --git a/pkg/util/azure/credential_test.go b/pkg/util/azure/credential_test.go index 16381c5cdb..bdd33eadb0 100644 --- a/pkg/util/azure/credential_test.go +++ b/pkg/util/azure/credential_test.go @@ -47,7 +47,6 @@ func TestNewCredential(t *testing.T) { } _, err = NewCredential(creds, options) require.Nil(t, err) - } func Test_newConfigCredential(t *testing.T) { diff --git a/pkg/util/collections/includes_excludes_test.go b/pkg/util/collections/includes_excludes_test.go index fe084f4884..655e3a50e3 100644 --- a/pkg/util/collections/includes_excludes_test.go +++ b/pkg/util/collections/includes_excludes_test.go @@ -729,7 +729,6 @@ func TestGetScopedResourceIncludesExcludes(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - logger := logrus.StandardLogger() nsIncludeExclude := NewIncludesExcludes() resources := GetScopeResourceIncludesExcludes(setupDiscoveryClientWithResources(tc.apiResources), logger, tc.namespaceScopedIncludes, tc.namespaceScopedExcludes, tc.clusterScopedIncludes, tc.clusterScopedExcludes, *nsIncludeExclude) diff --git a/pkg/util/csi/util_test.go b/pkg/util/csi/util_test.go index a9b0a37aa3..8a3ea3cc1c 100644 --- a/pkg/util/csi/util_test.go +++ b/pkg/util/csi/util_test.go @@ -25,7 +25,6 @@ import ( ) func TestCSIFeatureNotEnabledAndPluginIsFromCSI(t *testing.T) { - features.NewFeatureFlagSet("EnableCSI") require.False(t, ShouldSkipAction("abc")) require.False(t, ShouldSkipAction("velero.io/csi-pvc-backupper")) diff --git a/pkg/util/kube/utils_test.go b/pkg/util/kube/utils_test.go index 31110dc8c0..141fb45cee 100644 --- a/pkg/util/kube/utils_test.go +++ b/pkg/util/kube/utils_test.go @@ -138,7 +138,6 @@ func TestEnsureNamespaceExistsAndIsReady(t *testing.T) { assert.Equal(t, test.expectedCreatedResult, nsCreated) }) } - } // TestGetVolumeDirectorySuccess tests that the GetVolumeDirectory function