Skip to content

Commit 365f3d2

Browse files
committed
fix: add more exec test for empty env
1 parent 79079bc commit 365f3d2

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

pkg/exec/command-ctx-builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (c CmdContextBuilder) Env(env ...string) CmdContextBuilder {
104104
// NOTE:
105105
// If we add here something and the default is set (.env == nil -> means use
106106
// os.Environ()) -> we need to add it back!
107-
if env != nil && c.cmdCtx.env == nil {
107+
if c.cmdCtx.env == nil && env != nil {
108108
c.cmdCtx.env = os.Environ()
109109
}
110110

pkg/exec/command-ctx_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ func TestCommandCtxPipeStdErr(t *testing.T) {
211211
assert.Contains(t, output, "this-is-not-existing")
212212
}
213213

214+
func TestCommandCtxEnvEmpty(t *testing.T) {
215+
envs := []string{}
216+
ctx := NewCmdCtxBuilder().Env(envs...).Build()
217+
218+
out, err := ctx.Get("env")
219+
require.NoError(t, err)
220+
assert.Contains(t, out, "PATH")
221+
}
222+
214223
func TestCommandCtxEnv(t *testing.T) {
215224
envs := []string{"A=banana", "B=monkey", "C=monkey"}
216225
ctx := NewCmdCtxBuilder().Env(envs...).Build()

0 commit comments

Comments
 (0)