From ce7d3b0e893d464b44135e25dd39eb7f874ddcf8 Mon Sep 17 00:00:00 2001 From: Carlos A Becker Date: Mon, 31 May 2021 01:53:40 +0000 Subject: [PATCH] test: default values for envs refs #1795 Signed-off-by: Carlos A Becker --- internal/tmpl/tmpl_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/tmpl/tmpl_test.go b/internal/tmpl/tmpl_test.go index 9488a4c15..75e77b269 100644 --- a/internal/tmpl/tmpl_test.go +++ b/internal/tmpl/tmpl_test.go @@ -140,6 +140,9 @@ func TestWithEnv(t *testing.T) { func TestFuncMap(t *testing.T) { ctx := context.New(config.Project{ ProjectName: "proj", + Env: []string{ + "FOO=bar", + }, }) wd, err := os.Getwd() require.NoError(t, err) @@ -155,6 +158,16 @@ func TestFuncMap(t *testing.T) { Name: "replace", Expected: "1.24", }, + { + Template: `{{ if index .Env "SOME_ENV" }}{{ .Env.SOME_ENV }}{{ else }}default value{{ end }}`, + Name: "default value", + Expected: "default value", + }, + { + Template: `{{ if index .Env "FOO" }}{{ .Env.FOO }}{{ else }}default value{{ end }}`, + Name: "default value set", + Expected: "bar", + }, { Template: `{{ time "2006-01-02" }}`, Name: "time YYYY-MM-DD",