Skip to content

Commit f7a8955

Browse files
committed
Adjust some tests.
1 parent 1ae29da commit f7a8955

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

internal/controller/postgrescluster/pgbackrest_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,11 +2606,9 @@ func TestGenerateBackupJobIntent(t *testing.T) {
26062606
require.ParallelCapacity(t, 0)
26072607
ns := setupNamespace(t, cc)
26082608

2609-
recorder := events.NewRecorder(t, runtime.Scheme)
26102609
r := &Reconciler{
2611-
Client: cc,
2612-
Recorder: recorder,
2613-
Owner: ControllerName,
2610+
Client: cc,
2611+
Owner: ControllerName,
26142612
}
26152613

26162614
ctx := context.Background()
@@ -2916,6 +2914,9 @@ volumes:
29162914
})
29172915

29182916
t.Run("CloudLogVolumeAnnotationNoPvc", func(t *testing.T) {
2917+
recorder := events.NewRecorder(t, runtime.Scheme)
2918+
r.Recorder = recorder
2919+
29192920
cluster.Namespace = ns.Name
29202921
cluster.Annotations = map[string]string{}
29212922
cluster.Annotations[naming.PGBackRestCloudLogVolume] = "some-pvc"
@@ -2985,6 +2986,9 @@ volumes:
29852986
})
29862987

29872988
t.Run("CloudLogVolumeAnnotationPvcInPlace", func(t *testing.T) {
2989+
recorder := events.NewRecorder(t, runtime.Scheme)
2990+
r.Recorder = recorder
2991+
29882992
cluster.Namespace = ns.Name
29892993
cluster.Annotations = map[string]string{}
29902994
cluster.Annotations[naming.PGBackRestCloudLogVolume] = "another-pvc"
@@ -3063,11 +3067,8 @@ volumes:
30633067
claimName: another-pvc
30643068
`))
30653069

3066-
// No new events
3067-
assert.Equal(t, len(recorder.Events), 1)
3068-
assert.Equal(t, recorder.Events[0].Regarding.Name, cluster.Name)
3069-
assert.Equal(t, recorder.Events[0].Reason, "PGBackRestCloudLogVolumeNotFound")
3070-
assert.Equal(t, recorder.Events[0].Note, "persistentvolumeclaims \"some-pvc\" not found")
3070+
// No events created
3071+
assert.Equal(t, len(recorder.Events), 0)
30713072
})
30723073
}
30733074

internal/util/volumes_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ func TestAddVolumeAndMountsToPod(t *testing.T) {
2222
{Name: "other"},
2323
{Name: "pgbackrest"},
2424
},
25+
InitContainers: []corev1.Container{
26+
{Name: "initializer"},
27+
{Name: "another"},
28+
},
2529
}
2630

2731
volume := &corev1.PersistentVolumeClaim{
@@ -31,8 +35,8 @@ func TestAddVolumeAndMountsToPod(t *testing.T) {
3135
}
3236

3337
alwaysExpect := func(t testing.TB, result *corev1.PodSpec) {
34-
// Only Containers and Volumes fields have changed.
35-
assert.DeepEqual(t, *pod, *result, cmpopts.IgnoreFields(*pod, "Containers", "Volumes"))
38+
// Only Containers, InitContainers, and Volumes fields have changed.
39+
assert.DeepEqual(t, *pod, *result, cmpopts.IgnoreFields(*pod, "Containers", "InitContainers", "Volumes"))
3640

3741
// Volume is mounted to all containers
3842
assert.Assert(t, cmp.MarshalMatches(result.Containers, `
@@ -47,6 +51,20 @@ func TestAddVolumeAndMountsToPod(t *testing.T) {
4751
- mountPath: /volumes/volume-name
4852
name: volume-name
4953
- name: pgbackrest
54+
resources: {}
55+
volumeMounts:
56+
- mountPath: /volumes/volume-name
57+
name: volume-name
58+
`))
59+
60+
// Volume is mounted to all init containers
61+
assert.Assert(t, cmp.MarshalMatches(result.InitContainers, `
62+
- name: initializer
63+
resources: {}
64+
volumeMounts:
65+
- mountPath: /volumes/volume-name
66+
name: volume-name
67+
- name: another
5068
resources: {}
5169
volumeMounts:
5270
- mountPath: /volumes/volume-name

0 commit comments

Comments
 (0)