@@ -34,7 +34,8 @@ import (
3434 "github.com/stretchr/testify/require"
3535)
3636
37- func newPostgresClusterAdmissionReview (uid string , op admissionv1.Operation , obj * enterpriseApi.PostgresCluster , oldObj * enterpriseApi.PostgresCluster ) * admissionv1.AdmissionReview {
37+ func newPostgresClusterAdmissionReview (t * testing.T , uid string , op admissionv1.Operation , obj * enterpriseApi.PostgresCluster , oldObj * enterpriseApi.PostgresCluster ) * admissionv1.AdmissionReview {
38+ t .Helper ()
3839 ar := & admissionv1.AdmissionReview {
3940 TypeMeta : metav1.TypeMeta {
4041 APIVersion : "admission.k8s.io/v1" ,
@@ -56,20 +57,21 @@ func newPostgresClusterAdmissionReview(uid string, op admissionv1.Operation, obj
5657 Namespace : obj .Namespace ,
5758 Operation : op ,
5859 Object : runtime.RawExtension {
59- Raw : mustMarshal (obj ),
60+ Raw : mustMarshal (t , obj ),
6061 },
6162 UserInfo : authenticationv1.UserInfo {Username : "test-user" },
6263 },
6364 }
6465 if oldObj != nil {
6566 ar .Request .OldObject = runtime.RawExtension {
66- Raw : mustMarshal (oldObj ),
67+ Raw : mustMarshal (t , oldObj ),
6768 }
6869 }
6970 return ar
7071}
7172
72- func newPostgresClusterClassAdmissionReview (uid string , op admissionv1.Operation , obj * enterpriseApi.PostgresClusterClass , oldObj * enterpriseApi.PostgresClusterClass ) * admissionv1.AdmissionReview {
73+ func newPostgresClusterClassAdmissionReview (t * testing.T , uid string , op admissionv1.Operation , obj * enterpriseApi.PostgresClusterClass , oldObj * enterpriseApi.PostgresClusterClass ) * admissionv1.AdmissionReview {
74+ t .Helper ()
7375 ar := & admissionv1.AdmissionReview {
7476 TypeMeta : metav1.TypeMeta {
7577 APIVersion : "admission.k8s.io/v1" ,
@@ -90,14 +92,14 @@ func newPostgresClusterClassAdmissionReview(uid string, op admissionv1.Operation
9092 Name : obj .Name ,
9193 Operation : op ,
9294 Object : runtime.RawExtension {
93- Raw : mustMarshal (obj ),
95+ Raw : mustMarshal (t , obj ),
9496 },
9597 UserInfo : authenticationv1.UserInfo {Username : "test-user" },
9698 },
9799 }
98100 if oldObj != nil {
99101 ar .Request .OldObject = runtime.RawExtension {
100- Raw : mustMarshal (oldObj ),
102+ Raw : mustMarshal (t , oldObj ),
101103 }
102104 }
103105 return ar
@@ -305,7 +307,7 @@ func TestPostgresClusterPgHBAIntegration(t *testing.T) {
305307
306308 for _ , tt := range tests {
307309 t .Run (tt .name , func (t * testing.T ) {
308- ar := newPostgresClusterAdmissionReview ("uid-" + tt .name , admissionv1 .Create , tt .obj , nil )
310+ ar := newPostgresClusterAdmissionReview (t , "uid-" + tt .name , admissionv1 .Create , tt .obj , nil )
309311 resp := sendAdmissionReview (t , server , ar )
310312
311313 assert .Equal (t , tt .wantAllowed , resp .Allowed , "unexpected admission result" )
@@ -350,7 +352,7 @@ func TestPostgresClusterPgHBAUpdateIntegration(t *testing.T) {
350352 "hostssl all all 0.0.0.0/0 scram-sha-256" ,
351353 "local all all peer" ,
352354 }
353- ar := newPostgresClusterAdmissionReview ("uid-update-valid" , admissionv1 .Update , newObj , oldObj )
355+ ar := newPostgresClusterAdmissionReview (t , "uid-update-valid" , admissionv1 .Update , newObj , oldObj )
354356 resp := sendAdmissionReview (t , server , ar )
355357 assert .True (t , resp .Allowed )
356358 })
@@ -360,7 +362,7 @@ func TestPostgresClusterPgHBAUpdateIntegration(t *testing.T) {
360362 newObj .Spec .PgHBA = []string {
361363 "hostx all all 0.0.0.0/0 md5" ,
362364 }
363- ar := newPostgresClusterAdmissionReview ("uid-update-invalid" , admissionv1 .Update , newObj , oldObj )
365+ ar := newPostgresClusterAdmissionReview (t , "uid-update-invalid" , admissionv1 .Update , newObj , oldObj )
364366 resp := sendAdmissionReview (t , server , ar )
365367 assert .False (t , resp .Allowed )
366368 assert .Contains (t , resp .Result .Message , "unknown connection type" )
@@ -487,7 +489,7 @@ func TestPostgresClusterClassPgHBAIntegration(t *testing.T) {
487489
488490 for _ , tt := range tests {
489491 t .Run (tt .name , func (t * testing.T ) {
490- ar := newPostgresClusterClassAdmissionReview ("uid-" + tt .name , admissionv1 .Create , tt .obj , nil )
492+ ar := newPostgresClusterClassAdmissionReview (t , "uid-" + tt .name , admissionv1 .Create , tt .obj , nil )
491493 resp := sendAdmissionReview (t , server , ar )
492494
493495 assert .Equal (t , tt .wantAllowed , resp .Allowed , "unexpected admission result" )
@@ -529,7 +531,7 @@ func TestPostgresClusterClassPgHBAUpdateIntegration(t *testing.T) {
529531 "hostssl all all 0.0.0.0/0 scram-sha-256" ,
530532 "hostnossl all all 0.0.0.0/0 reject" ,
531533 }
532- ar := newPostgresClusterClassAdmissionReview ("uid-class-update-valid" , admissionv1 .Update , newObj , oldObj )
534+ ar := newPostgresClusterClassAdmissionReview (t , "uid-class-update-valid" , admissionv1 .Update , newObj , oldObj )
533535 resp := sendAdmissionReview (t , server , ar )
534536 assert .True (t , resp .Allowed )
535537 })
@@ -539,7 +541,7 @@ func TestPostgresClusterClassPgHBAUpdateIntegration(t *testing.T) {
539541 newObj .Spec .Config .PgHBA = []string {
540542 "host all all 0.0.0.0/0 bogus" ,
541543 }
542- ar := newPostgresClusterClassAdmissionReview ("uid-class-update-invalid" , admissionv1 .Update , newObj , oldObj )
544+ ar := newPostgresClusterClassAdmissionReview (t , "uid-class-update-invalid" , admissionv1 .Update , newObj , oldObj )
543545 resp := sendAdmissionReview (t , server , ar )
544546 assert .False (t , resp .Allowed )
545547 assert .Contains (t , resp .Result .Message , "unknown auth method" )
0 commit comments