diff --git a/library/common-test/tests/cnpg/cluster_validation_test.yaml b/library/common-test/tests/cnpg/cluster_validation_test.yaml index c379efc0..b38e898b 100644 --- a/library/common-test/tests/cnpg/cluster_validation_test.yaml +++ b/library/common-test/tests/cnpg/cluster_validation_test.yaml @@ -168,6 +168,32 @@ tests: - failedTemplate: errorMessage: CNPG Recovery - Expected [recovery.revision] to be a string, got [float64] + - it: should fail with pgVersion not a string + set: + cnpg: + my-pg: + enabled: true + user: test-user + database: test-db + mode: standalone + pgVersion: 5 + asserts: + - failedTemplate: + errorMessage: CNPG - Expected [pgVersion] to be a string, but got [float64] + + - it: should fail with invalid pgVersion + set: + cnpg: + my-pg: + enabled: true + user: test-user + database: test-db + mode: standalone + pgVersion: invalid + asserts: + - failedTemplate: + errorMessage: CNPG - Expected [pgVersion] to be one of [15, 16], but got [invalid] + - it: should fail with invalid recovery method set: cnpg: diff --git a/library/common/templates/lib/cnpg/cluster/_validation.tpl b/library/common/templates/lib/cnpg/cluster/_validation.tpl index b4f958e7..80943905 100644 --- a/library/common/templates/lib/cnpg/cluster/_validation.tpl +++ b/library/common/templates/lib/cnpg/cluster/_validation.tpl @@ -8,10 +8,15 @@ {{- end -}} {{- end -}} - {{- if (hasKey $objectData "version") -}} + {{- if $objectData.version -}} + {{- if not (kindIs "string" $objectData.pgVersion) -}} + {{/* We must ensure that this is a string, as it is used in image selector that require a string */}} + {{- fail (printf "CNPG - Expected [pgVersion] to be a string, but got [%s]" (kindOf $objectData.pgVersion)) -}} + {{- end -}} + {{- $validVersions := (list "15" "16") -}} - {{- if not (mustHas ( toString $objectData.version ) $validVersions) -}} - {{- fail (printf "CNPG - Expected [version] to be one of [%s], but got [%s]" (join ", " $validVersions) $objectData.version) -}} + {{- if not (mustHas $objectData.pgVersion $validVersions) -}} + {{- fail (printf "CNPG - Expected [pgVersion] to be one of [%s], but got [%s]" (join ", " $validVersions) $objectData.pgVersion) -}} {{- end -}} {{- end -}}