mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-06 21:36:30 +00:00
linter(testifylint): use Len or Empty for arrays testing (#7555)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -142,7 +142,7 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
|
||||
err = td.fakeClient.Get(ctx, td.req.NamespacedName, res)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Processed", string(res.Status.Phase))
|
||||
assert.Equal(t, 1, len(res.Status.Errors))
|
||||
assert.Len(t, res.Status.Errors, 1)
|
||||
assert.Equal(t, "spec.backupName is required", res.Status.Errors[0])
|
||||
})
|
||||
|
||||
@@ -210,7 +210,7 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
|
||||
err = td.fakeClient.Get(ctx, td.req.NamespacedName, res)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Processed", string(res.Status.Phase))
|
||||
assert.Equal(t, 1, len(res.Status.Errors))
|
||||
assert.Len(t, res.Status.Errors, 1)
|
||||
assert.Equal(t, "backup is still in progress", res.Status.Errors[0])
|
||||
})
|
||||
|
||||
@@ -225,7 +225,7 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
|
||||
err = td.fakeClient.Get(ctx, td.req.NamespacedName, res)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Processed", string(res.Status.Phase))
|
||||
assert.Equal(t, 1, len(res.Status.Errors))
|
||||
assert.Len(t, res.Status.Errors, 1)
|
||||
assert.Equal(t, "backup not found", res.Status.Errors[0])
|
||||
})
|
||||
t.Run("unable to find backup storage location", func(t *testing.T) {
|
||||
@@ -240,7 +240,7 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
|
||||
err = td.fakeClient.Get(ctx, td.req.NamespacedName, res)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Processed", string(res.Status.Phase))
|
||||
assert.Equal(t, 1, len(res.Status.Errors))
|
||||
assert.Len(t, res.Status.Errors, 1)
|
||||
assert.Equal(t, "backup storage location default not found", res.Status.Errors[0])
|
||||
})
|
||||
|
||||
@@ -257,7 +257,7 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
|
||||
err = td.fakeClient.Get(ctx, td.req.NamespacedName, res)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Processed", string(res.Status.Phase))
|
||||
assert.Equal(t, 1, len(res.Status.Errors))
|
||||
assert.Len(t, res.Status.Errors, 1)
|
||||
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) {
|
||||
@@ -688,7 +688,7 @@ func TestBackupDeletionControllerReconcile(t *testing.T) {
|
||||
err = td.fakeClient.Get(ctx, td.req.NamespacedName, res)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Processed", string(res.Status.Phase))
|
||||
assert.Equal(t, 1, len(res.Status.Errors))
|
||||
assert.Len(t, res.Status.Errors, 1)
|
||||
assert.Equal(t, "backup not found", res.Status.Errors[0])
|
||||
|
||||
})
|
||||
|
||||
@@ -492,7 +492,7 @@ func TestFindVolumeRestoresForPod(t *testing.T) {
|
||||
logger: logrus.New(),
|
||||
}
|
||||
requests := reconciler.findVolumeRestoresForPod(context.Background(), pod)
|
||||
assert.Len(t, requests, 0)
|
||||
assert.Empty(t, requests)
|
||||
|
||||
// contain one matching PVR
|
||||
reconciler.Client = clientBuilder.WithLists(&velerov1api.PodVolumeRestoreList{
|
||||
|
||||
@@ -592,7 +592,7 @@ func TestRestoreReconcile(t *testing.T) {
|
||||
return
|
||||
}
|
||||
if !test.addValidFinalizer {
|
||||
assert.Equal(t, 1, len(restorer.Calls))
|
||||
assert.Len(t, restorer.Calls, 1)
|
||||
}
|
||||
|
||||
// validate Patch call 2 (setting phase)
|
||||
|
||||
@@ -442,7 +442,7 @@ func TestPatchDynamicPVWithVolumeInfo(t *testing.T) {
|
||||
|
||||
errs := ctx.patchDynamicPVWithVolumeInfo()
|
||||
if tc.expectedErrNum > 0 {
|
||||
assert.Equal(t, tc.expectedErrNum, len(errs.Namespaces))
|
||||
assert.Len(t, errs.Namespaces, tc.expectedErrNum)
|
||||
}
|
||||
|
||||
for pvName, expectedPVInfo := range tc.expectedPatch {
|
||||
|
||||
@@ -219,16 +219,16 @@ func TestReconcileOfSchedule(t *testing.T) {
|
||||
// new backup shouldn't be submitted.
|
||||
if test.backup != nil &&
|
||||
(test.backup.Status.Phase == velerov1.BackupPhaseNew || test.backup.Status.Phase == velerov1.BackupPhaseInProgress) {
|
||||
assert.Equal(t, 1, len(backups.Items))
|
||||
assert.Len(t, backups.Items, 1)
|
||||
require.Nil(t, client.Delete(ctx, test.backup))
|
||||
}
|
||||
|
||||
require.Nil(t, client.List(ctx, backups))
|
||||
|
||||
if test.expectedBackupCreate == nil {
|
||||
assert.Equal(t, 0, len(backups.Items))
|
||||
assert.Empty(t, backups.Items)
|
||||
} else {
|
||||
assert.Equal(t, 1, len(backups.Items))
|
||||
assert.Len(t, backups.Items, 1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user