Skip to content

Commit

Permalink
Flush logger after a command is done executing (#85)
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Neumann <[email protected]>
  • Loading branch information
ANeumann82 authored May 13, 2020
1 parent e6259a4 commit 1de6ce9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/test/utils/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,9 @@ func RunCommands(logger Logger, namespace string, command string, commands []har
}
if bg != nil {
bgs = append(bgs, bg)
} else {
// We only need to flush if this is not a background command
logger.Flush()
}
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/test/utils/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Logger interface {
Logf(format string, args ...interface{})
WithPrefix(string) Logger
Write(p []byte) (n int, err error)
Flush()
}

// TestLogger implements the Logger interface to be compatible with the go test operator's
Expand Down Expand Up @@ -65,3 +66,10 @@ func (t *TestLogger) Write(p []byte) (n int, err error) {

return len(p), nil
}

func (t *TestLogger) Flush() {
if len(t.buffer) != 0 {
t.Log(string(t.buffer))
t.buffer = []byte{}
}
}

0 comments on commit 1de6ce9

Please sign in to comment.