Skip to content

Commit

Permalink
lint(ginkgolinter): expect (not)to HaveOccurred
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Mar 27, 2024
1 parent a2c87fc commit 16b8233
Show file tree
Hide file tree
Showing 47 changed files with 31 additions and 91 deletions.
1 change: 0 additions & 1 deletion internal/hook/hook_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions internal/hook/item_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions internal/hook/wait_exec_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion internal/resourcemodifiers/resource_modifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ func TestGetResourceModifiersFromConfig(t *testing.T) {
}

func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {

pvcStandardSc := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
Expand Down
3 changes: 0 additions & 3 deletions internal/resourcepolicies/volume_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func TestCapacityIsInRange(t *testing.T) {
actual := test.capacity.isInRange(test.quantity)

assert.Equal(t, test.isInRange, actual)

})
}
}
Expand Down Expand Up @@ -141,7 +140,6 @@ func TestStorageClassConditionMatch(t *testing.T) {
}

func TestNFSConditionMatch(t *testing.T) {

tests := []struct {
name string
condition *nfsCondition
Expand Down Expand Up @@ -196,7 +194,6 @@ func TestNFSConditionMatch(t *testing.T) {
}

func TestCSIConditionMatch(t *testing.T) {

tests := []struct {
name string
condition *csiCondition
Expand Down
4 changes: 2 additions & 2 deletions internal/storage/storagelocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
})
}
Expand Down
1 change: 0 additions & 1 deletion internal/velero/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion pkg/backup/item_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ func TestSortOrderedResource(t *testing.T) {
}
sortedPvResources := sortResourcesByOrder(log, pvResources, pvOrder)
assert.Equal(t, sortedPvResources, expectedPvResources)

}
2 changes: 0 additions & 2 deletions pkg/backup/remap_crd_version_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -217,7 +216,6 @@ func TestRemapCRDVersionActionData(t *testing.T) {
betaClient.Delete(context.TODO(), crd.Name, metav1.DeleteOptions{})
})
}

}

func fakeDiscoveryHelper() velerodiscovery.Helper {
Expand Down
2 changes: 0 additions & 2 deletions pkg/backup/service_account_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ func TestServiceAccountActionExecute(t *testing.T) {
assert.Equal(t, test.expectedAdditionalItems, additional)
})
}

}

func TestServiceAccountActionExecuteOnBeta1(t *testing.T) {
Expand Down Expand Up @@ -608,5 +607,4 @@ func TestServiceAccountActionExecuteOnBeta1(t *testing.T) {
assert.Equal(t, test.expectedAdditionalItems, additional)
})
}

}
1 change: 0 additions & 1 deletion pkg/buildinfo/buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ func TestFormattedGitSHA(t *testing.T) {
assert.Equal(t, FormattedGitSHA(), test.expected)
})
}

}
1 change: 0 additions & 1 deletion pkg/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func removeConfigfileName() error {
return nil
}
func TestConfigOperations(t *testing.T) {

preHomeEnv := ""
prevEnv := os.Environ()
for _, entry := range prevEnv {
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/cli/backup/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,13 @@ func TestCreateOptions_OrderedResources(t *testing.T) {
"persistentvolumes": "pv1,pv2",
}
assert.Equal(t, orderedResources, expectedMixedResources)

}

func TestCreateCommand(t *testing.T) {
name := "nameToBeCreated"
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{}

Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/cli/backuplocation/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
)

func TestNewDeleteCommand(t *testing.T) {

// create a factory
f := &factorymocks.Factory{}
kbclient := velerotest.NewFakeControllerRuntimeClient(t)
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/cli/restore/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/util/flag/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func TestSetOfMap(t *testing.T) {
assert.EqualValues(t, c.expected, m.Data())
})
}

}

func TestStringOfMap(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/util/output/backup_structured_describer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,5 +618,4 @@ func TestDescribeDeleteBackupRequestsInSF(t *testing.T) {
assert.True(tt, reflect.DeepEqual(sd.output, tc.expect))
})
}

}
2 changes: 0 additions & 2 deletions pkg/controller/backup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1735,6 +1734,5 @@ func TestPatchResourceWorksWithStatus(t *testing.T) {
t.Error(cmp.Diff(fromCluster, tt.args.updated))
}
})

}
}
5 changes: 0 additions & 5 deletions pkg/controller/backup_deletion_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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])

})
}

Expand Down
1 change: 0 additions & 1 deletion pkg/controller/backup_repository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func mockBackupRepositoryCR() *velerov1api.BackupRepository {
MaintenanceFrequency: metav1.Duration{Duration: testMaintenanceFrequency},
},
}

}

func TestPatchBackupRepository(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/backup_storage_location_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/backup_sync_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions pkg/controller/data_download_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -813,7 +812,6 @@ func TestTryCancelDataDownload(t *testing.T) {
}

func TestUpdateDataDownloadWithRetry(t *testing.T) {

namespacedName := types.NamespacedName{
Name: dataDownloadName,
Namespace: "velero",
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/data_upload_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ func TestTryCancelDataUpload(t *testing.T) {
}

func TestUpdateDataUploadWithRetry(t *testing.T) {

namespacedName := types.NamespacedName{
Name: dataUploadName,
Namespace: "velero",
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 16b8233

Please sign in to comment.