Skip to content

Commit 6f047a5

Browse files
committed
Provide interface so cmd can be easily mocked
1 parent 30da661 commit 6f047a5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

command.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@ import (
1111
"time"
1212
)
1313

14+
type CommandInterface interface {
15+
AddEnv(string, string)
16+
Stdout() string
17+
Stderr() string
18+
Combined() string
19+
ExitCode() int
20+
Executed() bool
21+
ExecuteContext(context.Context) error
22+
Execute() error
23+
}
24+
25+
var _ CommandInterface = (*Command)(nil)
26+
1427
// Command represents a single command which can be executed
1528
type Command struct {
1629
Command string
@@ -165,7 +178,7 @@ func WithEnvironmentVariables(env EnvVars) func(c *Command) {
165178

166179
// AddEnv adds an environment variable to the command
167180
// If a variable gets passed like ${VAR_NAME} the env variable will be read out by the current shell
168-
func (c *Command) AddEnv(key string, value string) {
181+
func (c *Command) AddEnv(key, value string) {
169182
value = os.ExpandEnv(value)
170183
c.Env = append(c.Env, fmt.Sprintf("%s=%s", key, value))
171184
}

0 commit comments

Comments
 (0)