Merge pull request #8071 from kaovilai/static-checks

static checks
This commit is contained in:
Xun Jiang/Bruce Jiang
2024-08-04 19:49:52 +08:00
committed by GitHub
4 changed files with 9 additions and 15 deletions

View File

@@ -33,7 +33,7 @@ import (
const testMaintenanceFrequency = 10 * time.Minute
func mockBackupRepoReconciler(t *testing.T, rr *velerov1api.BackupRepository, mockOn string, arg interface{}, ret interface{}) *BackupRepoReconciler {
func mockBackupRepoReconciler(t *testing.T, mockOn string, arg interface{}, ret interface{}) *BackupRepoReconciler {
mgr := &repomokes.Manager{}
if mockOn != "" {
mgr.On(mockOn, arg).Return(ret)
@@ -61,7 +61,7 @@ func mockBackupRepositoryCR() *velerov1api.BackupRepository {
func TestPatchBackupRepository(t *testing.T) {
rr := mockBackupRepositoryCR()
reconciler := mockBackupRepoReconciler(t, rr, "", nil, nil)
reconciler := mockBackupRepoReconciler(t, "", nil, nil)
err := reconciler.Client.Create(context.TODO(), rr)
assert.NoError(t, err)
err = reconciler.patchBackupRepository(context.Background(), rr, repoReady())
@@ -77,7 +77,7 @@ func TestCheckNotReadyRepo(t *testing.T) {
rr.Spec.BackupStorageLocation = "default"
rr.Spec.ResticIdentifier = "fake-identifier"
rr.Spec.VolumeNamespace = "volume-ns-1"
reconciler := mockBackupRepoReconciler(t, rr, "PrepareRepo", rr, nil)
reconciler := mockBackupRepoReconciler(t, "PrepareRepo", rr, nil)
err := reconciler.Client.Create(context.TODO(), rr)
assert.NoError(t, err)
locations := &velerov1api.BackupStorageLocation{
@@ -100,7 +100,7 @@ func TestCheckNotReadyRepo(t *testing.T) {
func TestRunMaintenanceIfDue(t *testing.T) {
rr := mockBackupRepositoryCR()
reconciler := mockBackupRepoReconciler(t, rr, "PruneRepo", rr, nil)
reconciler := mockBackupRepoReconciler(t, "PruneRepo", rr, nil)
err := reconciler.Client.Create(context.TODO(), rr)
assert.NoError(t, err)
lastTm := rr.Status.LastMaintenanceTime
@@ -118,7 +118,7 @@ func TestRunMaintenanceIfDue(t *testing.T) {
func TestInitializeRepo(t *testing.T) {
rr := mockBackupRepositoryCR()
rr.Spec.BackupStorageLocation = "default"
reconciler := mockBackupRepoReconciler(t, rr, "PrepareRepo", rr, nil)
reconciler := mockBackupRepoReconciler(t, "PrepareRepo", rr, nil)
err := reconciler.Client.Create(context.TODO(), rr)
assert.NoError(t, err)
locations := &velerov1api.BackupStorageLocation{
@@ -189,7 +189,7 @@ func TestBackupRepoReconcile(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
reconciler := mockBackupRepoReconciler(t, test.repo, "", test.repo, nil)
reconciler := mockBackupRepoReconciler(t, "", test.repo, nil)
err := reconciler.Client.Create(context.TODO(), test.repo)
assert.NoError(t, err)
_, err = reconciler.Reconcile(context.TODO(), ctrl.Request{NamespacedName: types.NamespacedName{Namespace: test.repo.Namespace, Name: test.repo.Name}})

View File

@@ -144,7 +144,7 @@ func defaultLocationWithLongerLocationName(namespace string) *velerov1api.Backup
}
}
func numBackups(c ctrlClient.WithWatch, ns string) (int, error) {
func numBackups(c ctrlClient.WithWatch) (int, error) {
var existingK8SBackups velerov1api.BackupList
err := c.List(context.TODO(), &existingK8SBackups, &ctrlClient.ListOptions{})
if err != nil {
@@ -692,7 +692,7 @@ var _ = Describe("Backup Sync Reconciler", func() {
}
r.deleteOrphanedBackups(ctx, bslName, test.cloudBackups, velerotest.NewLogger())
numBackups, err := numBackups(client, r.namespace)
numBackups, err := numBackups(client)
Expect(err).ShouldNot(HaveOccurred())
fmt.Println("")

View File

@@ -613,12 +613,6 @@ func TestRestoreReconcile(t *testing.T) {
},
}
if test.restore.Spec.ScheduleName != "" && test.backup != nil {
expected.Spec = SpecPatch{
BackupName: test.backup.Name,
}
}
if test.expectedStartTime != nil {
expected.Status.StartTimestamp = test.expectedStartTime
}

View File

@@ -311,7 +311,7 @@ func (ctx *finalizerContext) patchDynamicPVWithVolumeInfo() (errs results.Result
// We are handling a common but specific scenario where a PVC is in a pending state and uses a storage class with
// VolumeBindingMode set to WaitForFirstConsumer. In this case, the PV patch step is skipped to avoid
// failures due to the PVC not being bound, which could cause a timeout and result in a failed restore.
if pvc != nil && pvc.Status.Phase == v1.ClaimPending {
if pvc.Status.Phase == v1.ClaimPending {
// check if storage class used has VolumeBindingMode as WaitForFirstConsumer
scName := *pvc.Spec.StorageClassName
sc := &storagev1api.StorageClass{}