From cfed7dd3ef75ea650a77905b70965d13a8953b1e Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Fri, 10 Feb 2023 16:12:46 +0200 Subject: [PATCH] another case --- .../tests/container/lifecycle_test.yaml | 23 +++++++++++++++++++ .../lib/container/actions/_httpGet.tpl | 6 +++++ 2 files changed, 29 insertions(+) diff --git a/library/common-test/tests/container/lifecycle_test.yaml b/library/common-test/tests/container/lifecycle_test.yaml index dce725f990..2d99b8ddc0 100644 --- a/library/common-test/tests/container/lifecycle_test.yaml +++ b/library/common-test/tests/container/lifecycle_test.yaml @@ -217,6 +217,29 @@ tests: - failedTemplate: errorMessage: Container - Expected non-empty on [http] type + - it: should fail with path not starting with / on http lifecycle type + set: + image: *image + workload: + workload-name: + enabled: true + primary: true + type: Deployment + podSpec: + containers: + container-name1: + enabled: true + primary: true + imageSelector: image + lifecycle: + preStop: + type: http + port: 80 + path: "api/v1" + asserts: + - failedTemplate: + errorMessage: Container - Expected to start with a forward slash [/] on type + - it: should fail with empty value on httpHeaders on http lifecycle type set: image: *image diff --git a/library/common/1.0.0/templates/lib/container/actions/_httpGet.tpl b/library/common/1.0.0/templates/lib/container/actions/_httpGet.tpl index eb9eb1b35f..702b9f9040 100644 --- a/library/common/1.0.0/templates/lib/container/actions/_httpGet.tpl +++ b/library/common/1.0.0/templates/lib/container/actions/_httpGet.tpl @@ -15,9 +15,15 @@ objectData: The object data to be used to render the container. {{- if kindIs "string" $port -}} {{- $port = tpl $port $rootCtx -}} {{- end -}} + {{- with $objectData.path -}} {{- $path = tpl . $rootCtx -}} {{- end -}} + + {{- if not (hasPrefix "/" $path) -}} + {{- fail "Container - Expected to start with a forward slash [/] on type" -}} + {{- end -}} + {{- with $objectData.scheme -}} {{- $scheme = tpl . $rootCtx -}} {{- end }}