Skip to content

Commit

Permalink
test: Log command output at fail level if action failed
Browse files Browse the repository at this point in the history
Log expected command failure at info level so that it is easier to
reason about the following flow logs, if any.

Always consider any stderr output as a failure and log it at fail
level.

Log stdout at fail level if the action failed, and at the debug level
otherwise.

This helps diagnoze test failures also when `--debug` is not on.

Signed-off-by: Jarno Rajahalme <[email protected]>
  • Loading branch information
jrajahalme committed Jun 16, 2021
1 parent 3af4421 commit aba3152
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions connectivity/check/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,32 @@ func (a *Action) ExecInPod(ctx context.Context, cmd []string) {
cmdName := cmd[0]
cmdStr := strings.Join(cmd, " ")

if stderr.Len() > 0 {
a.test.Debugf("%s stderr: %s", cmdName, stderr.String())
} else if stdout.Len() > 0 {
a.test.Debugf("%s stdout: %s", cmdName, stdout.String())
}

if err != nil || stderr.Len() > 0 {
if a.shouldSucceed() {
a.Failf("command %q failed: %s", cmdStr, err)
} else {
a.test.Debugf("command %q failed as expected: %s", cmdStr, err)
a.test.Infof("command %q failed as expected: %s", cmdStr, err)
}
} else {
if !a.shouldSucceed() {
a.Failf("command %q succeeded while it should have failed: %s", cmdStr, stdout.String())
}
}
if stderr.Len() > 0 {
// Any stderr output is considered a test failure.
a.Failf("%s stderr: %s", cmdName, stderr.String())
}
if stdout.Len() > 0 {
// Debug level logs are only shown when running with `--debug`,
// which is proper for succeeding actions. Log at the fail
// level when the action has failed to always log the failing
// output.
if a.failed {
a.Failf("%s stdout: %s", cmdName, stdout.String())
} else {
a.Debugf("%s stdout: %s", cmdName, stdout.String())
}
}
}

// shouldSucceed returns true if no drops are expected in either direction.
Expand Down

0 comments on commit aba3152

Please sign in to comment.