diff --git a/library/common-test/tests/portal/portal_path_test.yaml b/library/common-test/tests/portal/portal_path_test.yaml new file mode 100644 index 0000000000..f04cbac0c9 --- /dev/null +++ b/library/common-test/tests/portal/portal_path_test.yaml @@ -0,0 +1,189 @@ +suite: portal path test +templates: + - common.yaml +tests: + - it: should pass with default values + documentIndex: &deploymentDoc 0 + asserts: + - hasDocuments: + count: 3 + - isKind: + of: Deployment + + - it: should fail with portal override with empty path + set: + portal: + main: + main: + path: + service: + main: + enabled: true + ports: + main: + enabled: true + port: 10000 + targetPort: 80 + asserts: + - failedTemplate: + errorMessage: You have defined empty in . Define a path or remove the key. + + - it: should pass with defaults on single service/port + documentIndex: &portalDoc 2 + set: + service: + main: + enabled: true + ports: + main: + enabled: true + port: 10000 + protocol: HTTP + targetPort: 80 + asserts: + - isKind: + of: ConfigMap + - isAPIVersion: + of: v1 + - equal: + path: metadata.name + value: portal + - isSubset: + path: data + content: + path-main-main: / + + - it: should pass with path override on single service/port + documentIndex: *portalDoc + set: + portal: + main: + main: + path: /some_path + service: + main: + enabled: true + ports: + main: + enabled: true + port: 10000 + targetPort: 80 + asserts: + - isKind: + of: ConfigMap + - isAPIVersion: + of: v1 + - equal: + path: metadata.name + value: portal + - isSubset: + path: data + content: + path-main-main: /some_path + + - it: should pass with defaults on multiple service/port + documentIndex: &dualServicePortalDoc 3 + set: + service: + main: + enabled: true + ports: + main: + enabled: true + primary: true + port: 10000 + protocol: HTTP + targetPort: 80 + main2: + enabled: true + port: 10001 + protocol: HTTP + targetPort: 80 + other: + enabled: true + ports: + other: + enabled: true + primary: true + port: 10002 + protocol: HTTP + targetPort: 80 + other2: + enabled: true + port: 10003 + protocol: HTTP + targetPort: 80 + asserts: + - isKind: + of: ConfigMap + - isAPIVersion: + of: v1 + - equal: + path: metadata.name + value: portal + - isSubset: + path: data + content: + path-main-main: / + path-main-main2: / + path-other-other: / + path-other-other2: / + + - it: should pass with override on multiple service/port + documentIndex: *dualServicePortalDoc + set: + portal: + main: + main: + path: /some_path1 + main2: + path: /some_path2 + other: + other: + path: /some_path3 + other2: + path: /some_path4 + service: + main: + enabled: true + ports: + main: + enabled: true + primary: true + port: 10000 + protocol: HTTP + targetPort: 80 + main2: + enabled: true + port: 10001 + protocol: HTTP + targetPort: 80 + other: + enabled: true + ports: + other: + enabled: true + primary: true + port: 10002 + protocol: HTTP + targetPort: 80 + other2: + enabled: true + port: 10003 + protocol: HTTP + targetPort: 80 + asserts: + - isKind: + of: ConfigMap + - isAPIVersion: + of: v1 + - equal: + path: metadata.name + value: portal + - isSubset: + path: data + content: + path-main-main: /some_path1 + path-main-main2: /some_path2 + path-other-other: /some_path3 + path-other-other2: /some_path4 diff --git a/library/common/1.0.0/templates/lib/portal/_path.tpl b/library/common/1.0.0/templates/lib/portal/_path.tpl index 64ea891fa0..fa0acc84ef 100644 --- a/library/common/1.0.0/templates/lib/portal/_path.tpl +++ b/library/common/1.0.0/templates/lib/portal/_path.tpl @@ -15,7 +15,7 @@ {{- if eq $portName $name -}} {{- if (hasKey $port "path") -}} {{- $portalPath = (tpl (toString $port.path) $root) -}} - {{- if not $portalPath -}} + {{- if or (eq $portalPath "") (not $portalPath) -}} {{/* toString on a nil key returns the string "" */}} {{- fail "You have defined empty in . Define a path or remove the key." -}} {{- end -}} {{- end -}}