From d88b9df1826b1ca6fb6faaeb422538429d4ec6ca Mon Sep 17 00:00:00 2001 From: apostasie Date: Wed, 16 Apr 2025 19:02:15 -0700 Subject: [PATCH] Allow per-command environment override While test allow declaration of custom environment variables, they must be set during the test declaration, apply to all commands, and cannot be altered during lifecycle operations (eg: Setup). This provides the ability to set variables for specific, individual commands. Signed-off-by: apostasie --- mod/tigron/.golangci.yml | 2 +- mod/tigron/test/command.go | 4 ++++ mod/tigron/test/interfaces.go | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mod/tigron/.golangci.yml b/mod/tigron/.golangci.yml index ab1817e4d1a..e5ce1567ab6 100644 --- a/mod/tigron/.golangci.yml +++ b/mod/tigron/.golangci.yml @@ -57,7 +57,7 @@ linters: settings: interfacebloat: # Default is 10 - max: 13 + max: 20 revive: enable-all-rules: true rules: diff --git a/mod/tigron/test/command.go b/mod/tigron/test/command.go index 0c1970d8d81..39d7f606e74 100644 --- a/mod/tigron/test/command.go +++ b/mod/tigron/test/command.go @@ -126,6 +126,10 @@ func (gc *GenericCommand) Feed(r io.Reader) { gc.cmd.Feed(r) } +func (gc *GenericCommand) Setenv(key, value string) { + gc.cmd.Env[key] = value +} + func (gc *GenericCommand) WithFeeder(fun func() io.Reader) { gc.cmd.WithFeeder(fun) } diff --git a/mod/tigron/test/interfaces.go b/mod/tigron/test/interfaces.go index 07f348999c5..a4d250d87fa 100644 --- a/mod/tigron/test/interfaces.go +++ b/mod/tigron/test/interfaces.go @@ -89,6 +89,8 @@ type TestableCommand interface { WithCwd(path string) // WithTimeout defines the execution timeout for a command. WithTimeout(timeout time.Duration) + // Setenv allows to override a specific env variable directly for a specific command instead of test-wide + Setenv(key, value string) // WithFeeder allows passing a reader to be fed to the command stdin. WithFeeder(fun func() io.Reader) // Feed allows passing a reader to be fed to the command stdin.