From 0b22d0581b739e56c9652a963b3c5c20ac7e0ac3 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 19 Mar 2026 22:58:42 +0200 Subject: task 257: add env-aware integration command helper --- integrationtests/commandutils.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'integrationtests/commandutils.go') diff --git a/integrationtests/commandutils.go b/integrationtests/commandutils.go index 86feee2..b7e9cf8 100644 --- a/integrationtests/commandutils.go +++ b/integrationtests/commandutils.go @@ -16,7 +16,11 @@ import ( func runCommand(ctx context.Context, t *testing.T, stdoutFile, cmdStr string, args ...string) (int, error) { + return runCommandWithEnv(ctx, t, stdoutFile, cmdStr, nil, args...) +} +func runCommandWithEnv(ctx context.Context, t *testing.T, stdoutFile, cmdStr string, + env map[string]string, args ...string) (int, error) { if _, err := os.Stat(cmdStr); err != nil { return 0, fmt.Errorf("no such executable '%s', please compile first: %w", cmdStr, err) } @@ -35,6 +39,10 @@ func runCommand(ctx context.Context, t *testing.T, stdoutFile, cmdStr string, t.Log("Running command", cmdStr, strings.Join(args, " ")) cmd := exec.CommandContext(ctx, cmdStr, args...) + cmd.Env = os.Environ() + for key, value := range env { + cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", key, value)) + } out, err := cmd.CombinedOutput() t.Log("Done running command!", err) if _, copyErr := io.Copy(fd, bytes.NewReader(out)); copyErr != nil { -- cgit v1.2.3