mirror of
https://github.com/truecharts/library-charts.git
synced 2026-07-03 18:04:23 -03:00
add more tests
This commit is contained in:
@@ -22,6 +22,9 @@ tests:
|
||||
set:
|
||||
operator: *operator
|
||||
ingress:
|
||||
my-ing:
|
||||
enabled: true
|
||||
primary: true
|
||||
my-ingress-super-long-name-that-is-longer-than-253-characters-my-configmap-super-long-name-that-is-longer-than-253-characters-my-configmap-super-long-name-that-is-longer-than-253-characters-my-configmap-super-long-long-long-long-long-long-long-long-name:
|
||||
enabled: true
|
||||
asserts:
|
||||
@@ -32,6 +35,9 @@ tests:
|
||||
set:
|
||||
operator: *operator
|
||||
ingress:
|
||||
my-ing:
|
||||
enabled: true
|
||||
primary: true
|
||||
_my-ingress:
|
||||
enabled: true
|
||||
asserts:
|
||||
@@ -44,6 +50,7 @@ tests:
|
||||
ingress:
|
||||
my-ingress:
|
||||
enabled: true
|
||||
primary: true
|
||||
namespace: my-extra-super-duper-long-name-that-is-longer-than-63-characters
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
@@ -58,6 +65,7 @@ tests:
|
||||
ingress:
|
||||
my-ingress:
|
||||
enabled: true
|
||||
primary: true
|
||||
namespace: my-namespace
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
@@ -69,6 +77,7 @@ tests:
|
||||
ingress:
|
||||
my-ingress:
|
||||
enabled: true
|
||||
primary: true
|
||||
labels: "not a dict"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
@@ -80,6 +89,7 @@ tests:
|
||||
ingress:
|
||||
my-ingress:
|
||||
enabled: true
|
||||
primary: true
|
||||
annotations: "not a dict"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
@@ -94,3 +104,56 @@ tests:
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Ingress - Expected the defined key [enabled] in [ingress.my-ingress] to not be empty
|
||||
|
||||
- it: should fail with targetSelector not a map
|
||||
set:
|
||||
operator: *operator
|
||||
ingress:
|
||||
my-ingress:
|
||||
enabled: true
|
||||
primary: true
|
||||
targetSelector: "not a map"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Ingress - Expected [targetSelector] to be a [map], but got [string]
|
||||
|
||||
- it: should fail with targetSelector having more than one key
|
||||
set:
|
||||
operator: *operator
|
||||
ingress:
|
||||
my-ingress:
|
||||
enabled: true
|
||||
primary: true
|
||||
targetSelector:
|
||||
main: main
|
||||
other: other
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Ingress - Expected [targetSelector] to have exactly one key, but got [2]
|
||||
|
||||
- it: should fail with targetSelector key missing value
|
||||
set:
|
||||
operator: *operator
|
||||
ingress:
|
||||
my-ingress:
|
||||
enabled: true
|
||||
primary: true
|
||||
targetSelector:
|
||||
main:
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Ingress - Expected [targetSelector.main] to have a value
|
||||
|
||||
- it: should fail with targetSelector key having non-string value
|
||||
set:
|
||||
operator: *operator
|
||||
ingress:
|
||||
my-ingress:
|
||||
enabled: true
|
||||
primary: true
|
||||
targetSelector:
|
||||
main:
|
||||
- not a string
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Ingress - Expected [targetSelector.main] to be a [string], but got [slice]
|
||||
|
||||
@@ -1,14 +1,77 @@
|
||||
{{/* Ingress Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.ingress.validation" (dict "objectData" $objectData) -}}
|
||||
{{ include "tc.v1.common.lib.ingress.validation" (dict "rootCtx" $ "objectData" $objectData) -}}
|
||||
objectData:
|
||||
rootCtx: The root context of the chart.
|
||||
objectData: The ingress object.
|
||||
objectData: The Ingress object.
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.lib.ingress.validation" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if $objectData.targetSelector -}}
|
||||
{{- if not (kindIs "map" $objectData.targetSelector) -}}
|
||||
{{- fail (printf "Ingress - Expected [targetSelector] to be a [map], but got [%s]" (kindOf $objectData.targetSelector)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $selectors := $objectData.targetSelector | keys | len -}}
|
||||
{{- if (gt $selectors 1) -}}
|
||||
{{ fail (printf "Ingress - Expected [targetSelector] to have exactly one key, but got [%d]" $selectors) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $k, $v := $objectData.targetSelector -}}
|
||||
{{- if not $v -}}
|
||||
{{- fail (printf "Ingress - Expected [targetSelector.%s] to have a value" $k) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not (kindIs "string" $v) -}}
|
||||
{{- fail (printf "Ingress - Expected [targetSelector.%s] to be a [string], but got [%s]" $k (kindOf $v)) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{/* Ingress Primary Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "tc.v1.common.lib.ingress.primaryValidation" $ -}}
|
||||
*/}}
|
||||
|
||||
{{- define "tc.v1.common.lib.ingress.primaryValidation" -}}
|
||||
|
||||
{{/* Initialize values */}}
|
||||
{{- $hasPrimary := false -}}
|
||||
{{- $hasEnabled := false -}}
|
||||
|
||||
{{- range $name, $ingress := $.Values.ingress -}}
|
||||
|
||||
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
|
||||
"rootCtx" $ "objectData" $ingress
|
||||
"name" $name "caller" "Ingress"
|
||||
"key" "ingress")) -}}
|
||||
|
||||
{{/* If ingress is enabled */}}
|
||||
{{- if eq $enabled "true" -}}
|
||||
{{- $hasEnabled = true -}}
|
||||
|
||||
{{/* And ingress is primary */}}
|
||||
{{- if and (hasKey $ingress "primary") ($ingress.primary) -}}
|
||||
{{/* Fail if there is already a primary ingress */}}
|
||||
{{- if $hasPrimary -}}
|
||||
{{- fail "Ingress - Only one ingress can be primary" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $hasPrimary = true -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Require at least one primary ingress, if any enabled */}}
|
||||
{{- if and $hasEnabled (not $hasPrimary) -}}
|
||||
{{- fail "Ingress - At least one enabled ingress must be primary" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
{{- define "tc.v1.common.spawner.ingress" -}}
|
||||
{{- $fullname := include "tc.v1.common.lib.chart.names.fullname" $ -}}
|
||||
|
||||
{{/* Generate named ingresses as required */}}
|
||||
{{/* Validate that only 1 primary exists */}}
|
||||
{{- include "tc.v1.common.lib.ingress.primaryValidation" $ -}}
|
||||
|
||||
{{- range $name, $ingress := .Values.ingress -}}
|
||||
|
||||
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
|
||||
@@ -44,7 +46,7 @@
|
||||
{{/* Perform validations */}}
|
||||
{{- include "tc.v1.common.lib.chart.names.validation" (dict "name" $objectName "length" 253) -}}
|
||||
{{- include "tc.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Ingress") -}}
|
||||
{{- /* include "tc.v1.common.lib.service.validation" (dict "rootCtx" $ "objectData" $objectData) */ -}}
|
||||
{{- include "tc.v1.common.lib.ingress.validation" (dict "rootCtx" $ "objectData" $objectData) -}}
|
||||
|
||||
{{/* Set the name of the ingress */}}
|
||||
{{- $_ := set $objectData "name" $objectName -}}
|
||||
|
||||
Reference in New Issue
Block a user