diff --git a/resource/command.go b/resource/command.go index 365867d2..1f81af67 100644 --- a/resource/command.go +++ b/resource/command.go @@ -49,7 +49,7 @@ func (c *Command) GetExec() string { } func (c *Command) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), idKey{}, c.ID()) + ctx := context.WithValue(context.Background(), system.CommandIDKey, c.ID()) skip := c.Skip if c.Timeout == 0 { diff --git a/system/command.go b/system/command.go index aea7ade9..ea97f17d 100644 --- a/system/command.go +++ b/system/command.go @@ -8,9 +8,17 @@ import ( "os/exec" "time" + "github.com/goss-org/goss/util" + ) +// CommandIDKeyType is the unique key for command IDs in context. +type CommandIDKeyType struct{} + +// CommandIDKey is the only instance that must be used everywhere. +var CommandIDKey = CommandIDKeyType{} + type Command interface { Command() string Exists() (bool, error) @@ -54,7 +62,8 @@ func (c *DefCommand) setup() error { c.exitStatus = cmd.Status stdoutB := cmd.Stdout.Bytes() stderrB := cmd.Stderr.Bytes() - id := c.Ctx.Value("id") + + id := c.Ctx.Value(CommandIDKey) logBytes(stdoutB, fmt.Sprintf("[Command][%s][stdout] ", id)) logBytes(stderrB, fmt.Sprintf("[Command][%s][stderr] ", id)) c.stdout = bytes.NewReader(stdoutB)