summaryrefslogtreecommitdiff
path: root/integrationtests/commandutils.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-19 22:58:42 +0200
committerPaul Buetow <paul@buetow.org>2026-03-19 22:58:42 +0200
commit0b22d0581b739e56c9652a963b3c5c20ac7e0ac3 (patch)
treec75713f66ceebbf386e69661ba4df7d05894f2a5 /integrationtests/commandutils.go
parentfb0791d88f32f25f23021493a26067c9aff22053 (diff)
task 257: add env-aware integration command helper
Diffstat (limited to 'integrationtests/commandutils.go')
-rw-r--r--integrationtests/commandutils.go8
1 files changed, 8 insertions, 0 deletions
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 {