@@ -549,37 +549,54 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
549549 envVarConstant : "CLONE_WALE_S3_PREFIX" ,
550550 envVarValue : "s3://another-bucket" ,
551551 },
552+ {
553+ envIndex : 20 ,
554+ envVarConstant : "CLONE_AWS_ENDPOINT" ,
555+ envVarValue : "s3.eu-central-1.amazonaws.com" ,
556+ },
552557 {
553558 envIndex : 19 ,
554559 envVarConstant : "CLONE_WAL_BUCKET_SCOPE_PREFIX" ,
555560 envVarValue : "" ,
556561 },
562+ }
563+ expectedCloneEnvWithPrefixSpec := []ExpectedValue {
557564 {
558565 envIndex : 20 ,
559- envVarConstant : "CLONE_AWS_ENDPOINT" ,
560- envVarValue : "s3.eu-central-1.amazonaws.com" ,
566+ envVarConstant : "CLONE_WALE_S3_PREFIX" ,
567+ envVarValue : "s3://another-bucket" ,
568+ },
569+ {
570+ envIndex : 16 ,
571+ envVarConstant : "clone_aws_endpoint" ,
572+ envVarValue : "s3.eu-west-1.amazonaws.com" ,
573+ },
574+ {
575+ envIndex : 15 ,
576+ envVarConstant : "CLONE_WAL_BUCKET_SCOPE_PREFIX" ,
577+ envVarValue : "spec-env-test" ,
561578 },
562579 }
563580 expectedCloneEnvConfigMap := []ExpectedValue {
564581 {
565- envIndex : 16 ,
582+ envIndex : 19 ,
566583 envVarConstant : "CLONE_WAL_S3_BUCKET" ,
567584 envVarValue : "global-s3-bucket" ,
568585 },
569586 {
570- envIndex : 17 ,
587+ envIndex : 20 ,
571588 envVarConstant : "CLONE_WAL_BUCKET_SCOPE_SUFFIX" ,
572589 envVarValue : fmt .Sprintf ("/%s" , dummyUUID ),
573590 },
574591 {
575- envIndex : 21 ,
592+ envIndex : 15 ,
576593 envVarConstant : "clone_aws_endpoint" ,
577594 envVarValue : "s3.eu-west-1.amazonaws.com" ,
578595 },
579596 }
580597 expectedCloneEnvSecret := []ExpectedValue {
581598 {
582- envIndex : 21 ,
599+ envIndex : 15 ,
583600 envVarConstant : "clone_aws_access_key_id" ,
584601 envVarValueRef : & v1.EnvVarSource {
585602 SecretKeyRef : & v1.SecretKeySelector {
@@ -593,12 +610,12 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
593610 }
594611 expectedStandbyEnvSecret := []ExpectedValue {
595612 {
596- envIndex : 15 ,
613+ envIndex : 18 ,
597614 envVarConstant : "STANDBY_WALE_GS_PREFIX" ,
598615 envVarValue : "gs://some/path/" ,
599616 },
600617 {
601- envIndex : 20 ,
618+ envIndex : 17 ,
602619 envVarConstant : "standby_google_application_credentials" ,
603620 envVarValueRef : & v1.EnvVarSource {
604621 SecretKeyRef : & v1.SecretKeySelector {
@@ -761,14 +778,36 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
761778 },
762779 },
763780 {
764- subTest : "will set CLONE_ parameters from spec and not global config or pod environment config map" ,
781+ subTest : "will set CLONE_ parameters from spec, if nothing env is set" ,
782+ opConfig : config.Config {},
783+ cloneDescription : & acidv1.CloneDescription {
784+ ClusterName : "test-cluster" ,
785+ EndTimestamp : "somewhen" ,
786+ UID : dummyUUID ,
787+ S3WalPath : "s3://another-bucket" ,
788+ S3Endpoint : "s3.eu-central-1.amazonaws.com" ,
789+ },
790+ standbyDescription : & acidv1.StandbyDescription {},
791+ expectedValues : expectedCloneEnvSpec ,
792+ },
793+ {
794+ subTest : "will set CLONE_ parameters from spec and override scope prefix" ,
765795 opConfig : config.Config {
766796 Resources : config.Resources {
767797 PodEnvironmentConfigMap : spec.NamespacedName {
768798 Name : testPodEnvironmentConfigMapName ,
769799 },
770800 },
771- WALES3Bucket : "global-s3-bucket" ,
801+ },
802+ pgsql : acidv1.Postgresql {
803+ Spec : acidv1.PostgresSpec {
804+ Env : []v1.EnvVar {
805+ {
806+ Name : "CLONE_WAL_BUCKET_SCOPE_PREFIX" ,
807+ Value : "spec-env-test" ,
808+ },
809+ },
810+ },
772811 },
773812 cloneDescription : & acidv1.CloneDescription {
774813 ClusterName : "test-cluster" ,
@@ -778,7 +817,7 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
778817 S3Endpoint : "s3.eu-central-1.amazonaws.com" ,
779818 },
780819 standbyDescription : & acidv1.StandbyDescription {},
781- expectedValues : expectedCloneEnvSpec ,
820+ expectedValues : expectedCloneEnvWithPrefixSpec ,
782821 },
783822 {
784823 subTest : "will set CLONE_AWS_ENDPOINT parameter from pod environment config map" ,
@@ -835,36 +874,39 @@ func TestGenerateSpiloPodEnvVars(t *testing.T) {
835874 }
836875
837876 for _ , tt := range tests {
838- c := newMockCluster (tt .opConfig )
839- pgsql := tt .pgsql
840- pgsql .Spec .Clone = tt .cloneDescription
841- pgsql .Spec .StandbyCluster = tt .standbyDescription
842- c .Postgresql = pgsql
843-
844- actualEnvs , err := c .generateSpiloPodEnvVars (& pgsql .Spec , types .UID (dummyUUID ), exampleSpiloConfig )
845- assert .NoError (t , err )
846-
847- for _ , ev := range tt .expectedValues {
848- env := actualEnvs [ev .envIndex ]
877+ t .Run (tt .subTest , func (t * testing.T ) {
878+ c := newMockCluster (tt .opConfig )
879+ pgsql := tt .pgsql
880+ pgsql .Spec .Clone = tt .cloneDescription
881+ pgsql .Spec .StandbyCluster = tt .standbyDescription
882+ c .Postgresql = pgsql
883+
884+ actualEnvs , err := c .generateSpiloPodEnvVars (& pgsql .Spec , types .UID (dummyUUID ), exampleSpiloConfig )
885+ assert .NoError (t , err )
886+
887+ for _ , ev := range tt .expectedValues {
888+ env := actualEnvs [ev .envIndex ]
889+
890+ if env .Name != ev .envVarConstant {
891+ t .Errorf ("%s %s: expected env name %s, have %s instead" ,
892+ testName , tt .subTest , ev .envVarConstant , env .Name )
893+ }
849894
850- if env .Name != ev .envVarConstant {
851- t .Errorf ("%s %s: expected env name %s, have %s instead" ,
852- testName , tt .subTest , ev .envVarConstant , env .Name )
853- }
895+ if ev .envVarValueRef != nil {
896+ if ! reflect .DeepEqual (env .ValueFrom , ev .envVarValueRef ) {
897+ t .Errorf ("%s %s: expected env value reference %#v, have %#v instead" ,
898+ testName , tt .subTest , ev .envVarValueRef , env .ValueFrom )
899+ }
900+ continue
901+ }
854902
855- if ev .envVarValueRef != nil {
856- if ! reflect .DeepEqual (env .ValueFrom , ev .envVarValueRef ) {
857- t .Errorf ("%s %s: expected env value reference %#v, have %#v instead" ,
858- testName , tt .subTest , ev .envVarValueRef , env .ValueFrom )
903+ if env .Value != ev .envVarValue {
904+ t .Errorf ("%s %s: expected env value %s, have %s instead" ,
905+ testName , tt .subTest , ev .envVarValue , env .Value )
859906 }
860- continue
861907 }
862908
863- if env .Value != ev .envVarValue {
864- t .Errorf ("%s %s: expected env value %s, have %s instead" ,
865- testName , tt .subTest , ev .envVarValue , env .Value )
866- }
867- }
909+ })
868910 }
869911}
870912
@@ -1060,19 +1102,21 @@ func TestCloneEnv(t *testing.T) {
10601102 }, k8sutil.KubernetesClient {}, acidv1.Postgresql {}, logger , eventRecorder )
10611103
10621104 for _ , tt := range tests {
1063- envs := cluster .generateCloneEnvironment (tt .cloneOpts )
1105+ t .Run (tt .subTest , func (t * testing.T ) {
1106+ envs := cluster .generateCloneEnvironment (tt .cloneOpts )
10641107
1065- env := envs [tt .envPos ]
1108+ env := envs [tt .envPos ]
10661109
1067- if env .Name != tt .env .Name {
1068- t .Errorf ("%s %s: Expected env name %s, have %s instead" ,
1069- testName , tt .subTest , tt .env .Name , env .Name )
1070- }
1110+ if env .Name != tt .env .Name {
1111+ t .Errorf ("%s %s: Expected env name %s, have %s instead" ,
1112+ testName , tt .subTest , tt .env .Name , env .Name )
1113+ }
10711114
1072- if env .Value != tt .env .Value {
1073- t .Errorf ("%s %s: Expected env value %s, have %s instead" ,
1074- testName , tt .subTest , tt .env .Value , env .Value )
1075- }
1115+ if env .Value != tt .env .Value {
1116+ t .Errorf ("%s %s: Expected env value %s, have %s instead" ,
1117+ testName , tt .subTest , tt .env .Value , env .Value )
1118+ }
1119+ })
10761120 }
10771121}
10781122
0 commit comments