1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-02-03 13:11:48 +02:00

fix: isEnvSet and envOrDefault not working sometimes

closes #5059
This commit is contained in:
Carlos Alexandro Becker 2024-08-08 10:50:37 -03:00
parent 5e4893234d
commit 3ae3a098e7
No known key found for this signature in database
2 changed files with 10 additions and 2 deletions

View File

@ -151,7 +151,7 @@ func (t *Template) WithEnvS(envs []string) *Template {
// WithEnv overrides template's env field with the given environment map.
func (t *Template) WithEnv(e map[string]string) *Template {
t.fields[env] = e
t.fields[env] = context.Env(e)
return t
}

View File

@ -178,7 +178,7 @@ func TestEnv(t *testing.T) {
}
}
func TestWithEnv(t *testing.T) {
func TestWithEnvS(t *testing.T) {
ctx := testctx.New(
testctx.WithEnv(map[string]string{"FOO": "BAR"}),
testctx.WithCurrentTag("v1.2.3"),
@ -198,6 +198,14 @@ func TestWithEnv(t *testing.T) {
out, err = tpl.Apply(`{{ range $idx, $key := .Env }}{{ $idx }},{{ end }}`)
require.NoError(t, err)
require.Equal(t, "BAR,FOO,NOVAL,", out)
out, err = tpl.Apply(`{{ envOrDefault "NOPE" "no" }}`)
require.NoError(t, err)
require.Equal(t, "no", out)
out, err = tpl.Apply(`{{ isEnvSet "NOPE" }}`)
require.NoError(t, err)
require.Equal(t, "false", out)
}
func TestFuncMap(t *testing.T) {