diff --git a/internal/cli/logs_test.go b/internal/cli/logs_test.go index 520d64a2f..9bff2f0df 100644 --- a/internal/cli/logs_test.go +++ b/internal/cli/logs_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "sync" "testing" "time" @@ -17,6 +18,18 @@ import ( "github.com/auth0/auth0-cli/internal/display" ) +// syncBuffer is a bytes.Buffer safe for the tail goroutine and renderer to write concurrently. +type syncBuffer struct { + mu sync.Mutex + buf bytes.Buffer +} + +func (b *syncBuffer) Write(p []byte) (int, error) { + b.mu.Lock() + defer b.mu.Unlock() + return b.buf.Write(p) +} + func TestTailLogsCommand(t *testing.T) { t.Run("it returns an error when it fails to get the logs on the first request", func(t *testing.T) { ctrl := gomock.NewController(t) @@ -123,8 +136,8 @@ API Operation Update branding settings cli := &cli{ renderer: &display.Renderer{ - MessageWriter: &bytes.Buffer{}, - ResultWriter: &bytes.Buffer{}, + MessageWriter: &syncBuffer{}, + ResultWriter: &syncBuffer{}, }, api: &auth0.API{Log: logsAPI}, }