Skip to content

Commit 5d39aed

Browse files
committed
test cleanup
1 parent f9a9c08 commit 5d39aed

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

internal/controller/postgrescluster/snapshots_test.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,17 @@ func TestReconcileVolumeSnapshots(t *testing.T) {
153153
},
154154
DeletionPolicy: "Delete",
155155
}
156-
err := r.Client.Create(ctx, volumeSnapshotClass)
157-
assert.NilError(t, err)
156+
assert.NilError(t, r.Client.Create(ctx, volumeSnapshotClass))
157+
t.Cleanup(func() { assert.Check(t, r.Client.Delete(ctx, volumeSnapshotClass)) })
158158

159159
// Create a cluster with snapshots enabled
160160
cluster := testCluster()
161161
cluster.Namespace = ns.Name
162162
cluster.Spec.Backups.Snapshots = &v1beta1.VolumeSnapshots{
163163
VolumeSnapshotClassName: volumeSnapshotClassName,
164164
}
165+
assert.NilError(t, r.Client.Create(ctx, cluster))
166+
t.Cleanup(func() { assert.Check(t, r.Client.Delete(ctx, cluster)) })
165167

166168
// Create pvc for reconcile
167169
pvc := &corev1.PersistentVolumeClaim{
@@ -188,15 +190,26 @@ func TestReconcileVolumeSnapshots(t *testing.T) {
188190
})
189191

190192
t.Run("SnapshotsEnabledReadySnapshotsExist", func(t *testing.T) {
191-
// volumeSnapshotClass still exists
193+
// Create a volume snapshot class
194+
volumeSnapshotClassName := "my-snapshotclass"
195+
volumeSnapshotClass := &volumesnapshotv1.VolumeSnapshotClass{
196+
ObjectMeta: metav1.ObjectMeta{
197+
Name: volumeSnapshotClassName,
198+
},
199+
DeletionPolicy: "Delete",
200+
}
201+
assert.NilError(t, r.Client.Create(ctx, volumeSnapshotClass))
202+
t.Cleanup(func() { assert.Check(t, r.Client.Delete(ctx, volumeSnapshotClass)) })
203+
192204
// Create a cluster with snapshots enabled
193205
cluster := testCluster()
194206
cluster.Namespace = ns.Name
195207
cluster.ObjectMeta.UID = "the-uid-123"
196-
volumeSnapshotClassName := "my-snapshotclass"
197208
cluster.Spec.Backups.Snapshots = &v1beta1.VolumeSnapshots{
198209
VolumeSnapshotClassName: volumeSnapshotClassName,
199210
}
211+
assert.NilError(t, r.Client.Create(ctx, cluster))
212+
t.Cleanup(func() { assert.Check(t, r.Client.Delete(ctx, cluster)) })
200213

201214
// Create pvc with annotation
202215
pvcName := initialize.String("dedicated-snapshot-volume")
@@ -301,15 +314,26 @@ func TestReconcileVolumeSnapshots(t *testing.T) {
301314
})
302315

303316
t.Run("SnapshotsEnabledCreateSnapshot", func(t *testing.T) {
304-
// volumeSnapshotClass still exists
317+
// Create a volume snapshot class
318+
volumeSnapshotClassName := "my-snapshotclass"
319+
volumeSnapshotClass := &volumesnapshotv1.VolumeSnapshotClass{
320+
ObjectMeta: metav1.ObjectMeta{
321+
Name: volumeSnapshotClassName,
322+
},
323+
DeletionPolicy: "Delete",
324+
}
325+
assert.NilError(t, r.Client.Create(ctx, volumeSnapshotClass))
326+
t.Cleanup(func() { assert.Check(t, r.Client.Delete(ctx, volumeSnapshotClass)) })
327+
305328
// Create a cluster with snapshots enabled
306329
cluster := testCluster()
307330
cluster.Namespace = ns.Name
308331
cluster.ObjectMeta.UID = "the-uid-123"
309-
volumeSnapshotClassName := "my-snapshotclass"
310332
cluster.Spec.Backups.Snapshots = &v1beta1.VolumeSnapshots{
311333
VolumeSnapshotClassName: volumeSnapshotClassName,
312334
}
335+
assert.NilError(t, r.Client.Create(ctx, cluster))
336+
t.Cleanup(func() { assert.Check(t, r.Client.Delete(ctx, cluster)) })
313337

314338
// Create pvc with annotation
315339
pvcName := initialize.String("dedicated-snapshot-volume")
@@ -840,7 +864,7 @@ func TestGetDedicatedSnapshotVolumeRestoreJob(t *testing.T) {
840864
func TestGetLatestCompleteBackupJob(t *testing.T) {
841865
ctx := context.Background()
842866
_, cc := setupKubernetes(t)
843-
require.ParallelCapacity(t, 1)
867+
// require.ParallelCapacity(t, 1)
844868

845869
r := &Reconciler{
846870
Client: cc,

0 commit comments

Comments
 (0)