diff --git a/changelogs/unreleased/10283-opbot-xd b/changelogs/unreleased/10283-opbot-xd new file mode 100644 index 000000000..5f7c3aa48 --- /dev/null +++ b/changelogs/unreleased/10283-opbot-xd @@ -0,0 +1 @@ +test: add verification for skippedPVTracker in backup tests diff --git a/pkg/backup/backup_test.go b/pkg/backup/backup_test.go index 0f3ff1be1..9574aa288 100644 --- a/pkg/backup/backup_test.go +++ b/pkg/backup/backup_test.go @@ -2931,7 +2931,6 @@ func (*fakeVolumeSnapshotter) DeleteSnapshot(snapshotID string) error { // looking at the backup request's VolumeSnapshots field. This test uses the fakeVolumeSnapshotter // struct in place of real volume snapshotters. func TestBackupWithSnapshots(t *testing.T) { - // TODO: add more verification for skippedPVTracker itemBlockPool := StartItemBlockWorkerPool(t.Context(), 1, logrus.StandardLogger()) defer itemBlockPool.Stop() tests := []struct { @@ -2941,6 +2940,7 @@ func TestBackupWithSnapshots(t *testing.T) { apiResources []*test.APIResource snapshotterGetter volumeSnapshotterGetter want []*volume.Snapshot + wantSkippedPVs []SkippedPV }{ { name: "persistent volume with no zone annotation creates a snapshot", @@ -2977,6 +2977,7 @@ func TestBackupWithSnapshots(t *testing.T) { }, }, }, + wantSkippedPVs: []SkippedPV{}, }, { name: "persistent volume with deprecated zone annotation creates a snapshot", @@ -3014,6 +3015,7 @@ func TestBackupWithSnapshots(t *testing.T) { }, }, }, + wantSkippedPVs: []SkippedPV{}, }, { name: "persistent volume with GA zone annotation creates a snapshot", @@ -3051,6 +3053,7 @@ func TestBackupWithSnapshots(t *testing.T) { }, }, }, + wantSkippedPVs: []SkippedPV{}, }, { name: "persistent volume with both GA and deprecated zone annotation creates a snapshot and should use the GA", @@ -3088,6 +3091,7 @@ func TestBackupWithSnapshots(t *testing.T) { }, }, }, + wantSkippedPVs: []SkippedPV{}, }, { name: "error returned from CreateSnapshot results in a failed snapshot", @@ -3123,6 +3127,7 @@ func TestBackupWithSnapshots(t *testing.T) { }, }, }, + wantSkippedPVs: []SkippedPV{}, }, { name: "backup with SnapshotVolumes=false does not create any snapshots", @@ -3144,6 +3149,17 @@ func TestBackupWithSnapshots(t *testing.T) { "default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "", "type-1", 100, false), }, want: nil, + wantSkippedPVs: []SkippedPV{ + { + Name: "pv-1", + Reasons: []PVSkipReason{ + { + Approach: volumeSnapshotApproach, + Reason: "not satisfy the criteria for VolumePolicy or the legacy snapshot way", + }, + }, + }, + }, }, { name: "backup with no volume snapshot locations does not create any snapshots", @@ -3162,6 +3178,17 @@ func TestBackupWithSnapshots(t *testing.T) { "default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "", "type-1", 100, false), }, want: nil, + wantSkippedPVs: []SkippedPV{ + { + Name: "pv-1", + Reasons: []PVSkipReason{ + { + Approach: volumeSnapshotApproach, + Reason: "no applicable volumesnapshotter found", + }, + }, + }, + }, }, { name: "backup with no volume snapshotters does not create any snapshots", @@ -3181,6 +3208,17 @@ func TestBackupWithSnapshots(t *testing.T) { }, snapshotterGetter: map[string]vsv1.VolumeSnapshotter{}, want: nil, + wantSkippedPVs: []SkippedPV{ + { + Name: "pv-1", + Reasons: []PVSkipReason{ + { + Approach: volumeSnapshotApproach, + Reason: "no applicable volumesnapshotter found", + }, + }, + }, + }, }, { name: "unsupported persistent volume type does not create any snapshots", @@ -3202,6 +3240,17 @@ func TestBackupWithSnapshots(t *testing.T) { "default": new(fakeVolumeSnapshotter), }, want: nil, + wantSkippedPVs: []SkippedPV{ + { + Name: "pv-1", + Reasons: []PVSkipReason{ + { + Approach: volumeSnapshotApproach, + Reason: "no applicable volumesnapshotter found", + }, + }, + }, + }, }, { name: "when there are multiple volumes, snapshot locations, and snapshotters, volumes are matched to the right snapshotters", @@ -3255,6 +3304,7 @@ func TestBackupWithSnapshots(t *testing.T) { }, }, }, + wantSkippedPVs: []SkippedPV{}, }, } @@ -3273,6 +3323,7 @@ func TestBackupWithSnapshots(t *testing.T) { require.NoError(t, err) assert.Equal(t, tc.want, tc.req.VolumeSnapshots.Get()) + assert.Equal(t, tc.wantSkippedPVs, tc.req.SkippedPVTracker.Summary()) }) } }