Skip to content

Commit

Permalink
Add headers to output when using logs tail
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Apr 12, 2023
1 parent ac090d1 commit 336e87c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ func (r *Renderer) Stream(data []View, ch <-chan View) {
}
}

if len(data) > 0 {
header := []string{
truncate("TYPE", 23),
truncate("DESCRIPTION", 54),
truncate("DATE", 20),
truncate("CONNECTION", 20),
truncate("CLIENT", 20),
}
displayRow(header)
}

for _, v := range data {
displayView(v)
}
Expand Down
7 changes: 5 additions & 2 deletions internal/display/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ func TestStream(t *testing.T) {

t.Run("Stream correctly handles nil channel", func(t *testing.T) {
mockRender.Stream(results, nil)
expectedResult := "API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A \n"
expectedResult := `TYPE DESCRIPTION DATE CONNECTION CLIENT
API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A
`
assert.Equal(t, expectedResult, stdout.String())
stdout.Reset()
})
Expand Down Expand Up @@ -93,7 +95,8 @@ func TestStream(t *testing.T) {

wg.Wait()

expectedResult := `API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A
expectedResult := `TYPE DESCRIPTION DATE CONNECTION CLIENT
API Operation Update branding settings Jan 01 00:00:00.000 N/A N/A
API Operation Update tenant settings Jan 01 00:00:00.000 N/A N/A
`
assert.Equal(t, expectedResult, stdout.String())
Expand Down

0 comments on commit 336e87c

Please sign in to comment.