Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resource/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion system/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down