@@ -413,7 +413,6 @@ func TestShmVolume(t *testing.T) {
413413 Volumes : []v1.Volume {},
414414 Containers : []v1.Container {
415415 {
416- Name : "postgres" ,
417416 VolumeMounts : []v1.VolumeMount {},
418417 },
419418 },
@@ -438,9 +437,10 @@ func TestShmVolume(t *testing.T) {
438437 }
439438 for _ , tt := range tests {
440439 addShmVolume (tt .podSpec )
440+ postgresContainer := getPostgresContainer (tt .podSpec )
441441
442442 volumeName := tt .podSpec .Volumes [tt .shmPos ].Name
443- volumeMountName := tt . podSpec . Containers [ 0 ] .VolumeMounts [tt .shmPos ].Name
443+ volumeMountName := postgresContainer .VolumeMounts [tt .shmPos ].Name
444444
445445 if volumeName != constants .ShmVolumeName {
446446 t .Errorf ("%s %s: Expected volume %s was not created, have %s instead" ,
@@ -612,8 +612,9 @@ func TestSecretVolume(t *testing.T) {
612612 for _ , tt := range tests {
613613 additionalSecretMount := "aws-iam-s3-role"
614614 additionalSecretMountPath := "/meta/credentials"
615+ postgresContainer := getPostgresContainer (tt .podSpec )
615616
616- numMounts := len (tt . podSpec . Containers [ 0 ] .VolumeMounts )
617+ numMounts := len (postgresContainer .VolumeMounts )
617618
618619 addSecretVolume (tt .podSpec , additionalSecretMount , additionalSecretMountPath )
619620
@@ -633,7 +634,8 @@ func TestSecretVolume(t *testing.T) {
633634 }
634635 }
635636
636- numMountsCheck := len (tt .podSpec .Containers [0 ].VolumeMounts )
637+ postgresContainer = getPostgresContainer (tt .podSpec )
638+ numMountsCheck := len (postgresContainer .VolumeMounts )
637639
638640 if numMountsCheck != numMounts + 1 {
639641 t .Errorf ("Unexpected number of VolumeMounts: got %v instead of %v" ,
@@ -865,7 +867,8 @@ func testEnvs(cluster *Cluster, podSpec *v1.PodTemplateSpec, role PostgresRole)
865867 "CONNECTION_POOLER_PORT" : false ,
866868 }
867869
868- envs := podSpec .Spec .Containers [0 ].Env
870+ container := getPostgresContainer (& podSpec .Spec )
871+ envs := container .Env
869872 for _ , env := range envs {
870873 required [env .Name ] = true
871874 }
@@ -1045,14 +1048,15 @@ func TestTLS(t *testing.T) {
10451048 }
10461049 assert .Contains (t , sts .Spec .Template .Spec .Volumes , volume , "the pod gets a secret volume" )
10471050
1048- assert .Contains (t , sts .Spec .Template .Spec .Containers [0 ].VolumeMounts , v1.VolumeMount {
1051+ postgresContainer := getPostgresContainer (& sts .Spec .Template .Spec )
1052+ assert .Contains (t , postgresContainer .VolumeMounts , v1.VolumeMount {
10491053 MountPath : "/tls" ,
10501054 Name : "my-secret" ,
10511055 }, "the volume gets mounted in /tls" )
10521056
1053- assert .Contains (t , sts . Spec . Template . Spec . Containers [ 0 ] .Env , v1.EnvVar {Name : "SSL_CERTIFICATE_FILE" , Value : "/tls/tls.crt" })
1054- assert .Contains (t , sts . Spec . Template . Spec . Containers [ 0 ] .Env , v1.EnvVar {Name : "SSL_PRIVATE_KEY_FILE" , Value : "/tls/tls.key" })
1055- assert .Contains (t , sts . Spec . Template . Spec . Containers [ 0 ] .Env , v1.EnvVar {Name : "SSL_CA_FILE" , Value : "/tls/ca.crt" })
1057+ assert .Contains (t , postgresContainer .Env , v1.EnvVar {Name : "SSL_CERTIFICATE_FILE" , Value : "/tls/tls.crt" })
1058+ assert .Contains (t , postgresContainer .Env , v1.EnvVar {Name : "SSL_PRIVATE_KEY_FILE" , Value : "/tls/tls.key" })
1059+ assert .Contains (t , postgresContainer .Env , v1.EnvVar {Name : "SSL_CA_FILE" , Value : "/tls/ca.crt" })
10561060}
10571061
10581062func TestAdditionalVolume (t * testing.T ) {
@@ -1147,7 +1151,7 @@ func TestAdditionalVolume(t *testing.T) {
11471151 }{
11481152 {
11491153 subTest : "checking volume mounts of postgres container" ,
1150- container : cluster . containerName () ,
1154+ container : constants . PostgresContainerName ,
11511155 expectedMounts : []string {"pgdata" , "test1" , "test3" , "test4" },
11521156 },
11531157 {
0 commit comments