Skip to content

Commit d88b9df

Browse files
committed
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 <[email protected]>
1 parent 88c6393 commit d88b9df

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

mod/tigron/.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ linters:
5757
settings:
5858
interfacebloat:
5959
# Default is 10
60-
max: 13
60+
max: 20
6161
revive:
6262
enable-all-rules: true
6363
rules:

mod/tigron/test/command.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ func (gc *GenericCommand) Feed(r io.Reader) {
126126
gc.cmd.Feed(r)
127127
}
128128

129+
func (gc *GenericCommand) Setenv(key, value string) {
130+
gc.cmd.Env[key] = value
131+
}
132+
129133
func (gc *GenericCommand) WithFeeder(fun func() io.Reader) {
130134
gc.cmd.WithFeeder(fun)
131135
}

mod/tigron/test/interfaces.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ type TestableCommand interface {
8989
WithCwd(path string)
9090
// WithTimeout defines the execution timeout for a command.
9191
WithTimeout(timeout time.Duration)
92+
// Setenv allows to override a specific env variable directly for a specific command instead of test-wide
93+
Setenv(key, value string)
9294
// WithFeeder allows passing a reader to be fed to the command stdin.
9395
WithFeeder(fun func() io.Reader)
9496
// Feed allows passing a reader to be fed to the command stdin.

0 commit comments

Comments
 (0)