testifylint: enable error-nil rule (#7670)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2024-07-16 18:23:16 +02:00
committed by GitHub
parent aa3fde5ea5
commit 35c90f1672
58 changed files with 218 additions and 219 deletions

View File

@@ -39,7 +39,7 @@ import (
// Test reconcile function of schedule controller. Pause is not covered as event filter will not allow it through
func TestReconcileOfSchedule(t *testing.T) {
require.Nil(t, velerov1.AddToScheme(scheme.Scheme))
require.NoError(t, velerov1.AddToScheme(scheme.Scheme))
newScheduleBuilder := func(phase velerov1.SchedulePhase) *builder.ScheduleBuilder {
return builder.ForSchedule("ns", "name").Phase(phase)
@@ -169,39 +169,39 @@ func TestReconcileOfSchedule(t *testing.T) {
reconciler.clock = testclocks.NewFakeClock(testTime)
if test.schedule != nil {
require.Nil(t, client.Create(ctx, test.schedule))
require.NoError(t, client.Create(ctx, test.schedule))
}
if test.backup != nil {
require.Nil(t, client.Create(ctx, test.backup))
require.NoError(t, client.Create(ctx, test.backup))
}
scheduleb4reconcile := &velerov1.Schedule{}
err = client.Get(ctx, types.NamespacedName{Namespace: "ns", Name: "name"}, scheduleb4reconcile)
if test.schedule != nil {
require.Nil(t, err)
require.NoError(t, err)
}
_, err = reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: types.NamespacedName{Namespace: "ns", Name: "name"}})
require.Nil(t, err)
require.NoError(t, err)
schedule := &velerov1.Schedule{}
err = client.Get(ctx, types.NamespacedName{Namespace: "ns", Name: "name"}, schedule)
if len(test.expectedPhase) > 0 {
require.Nil(t, err)
require.NoError(t, err)
assert.Equal(t, test.expectedPhase, string(schedule.Status.Phase))
}
if len(test.expectedValidationErrors) > 0 {
require.Nil(t, err)
require.NoError(t, err)
assert.EqualValues(t, test.expectedValidationErrors, schedule.Status.ValidationErrors)
}
if len(test.expectedLastBackup) > 0 {
require.Nil(t, err)
require.NoError(t, err)
require.NotNil(t, schedule.Status.LastBackup)
assert.Equal(t, parseTime(test.expectedLastBackup).Unix(), schedule.Status.LastBackup.Unix())
}
if len(test.expectedLastSkipped) > 0 {
require.Nil(t, err)
require.NoError(t, err)
require.NotNil(t, schedule.Status.LastSkipped)
assert.Equal(t, parseTime(test.expectedLastSkipped).Unix(), schedule.Status.LastSkipped.Unix())
}
@@ -213,17 +213,17 @@ func TestReconcileOfSchedule(t *testing.T) {
}
backups := &velerov1.BackupList{}
require.Nil(t, client.List(ctx, backups))
require.NoError(t, client.List(ctx, backups))
// If backup associated with schedule's status is in New or InProgress,
// new backup shouldn't be submitted.
if test.backup != nil &&
(test.backup.Status.Phase == velerov1.BackupPhaseNew || test.backup.Status.Phase == velerov1.BackupPhaseInProgress) {
assert.Len(t, backups.Items, 1)
require.Nil(t, client.Delete(ctx, test.backup))
require.NoError(t, client.Delete(ctx, test.backup))
}
require.Nil(t, client.List(ctx, backups))
require.NoError(t, client.List(ctx, backups))
if test.expectedBackupCreate == nil {
assert.Empty(t, backups.Items)
@@ -444,7 +444,7 @@ func TestGetBackup(t *testing.T) {
}
func TestCheckIfBackupInNewOrProgress(t *testing.T) {
require.Nil(t, velerov1.AddToScheme(scheme.Scheme))
require.NoError(t, velerov1.AddToScheme(scheme.Scheme))
client := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
logger := velerotest.NewLogger()