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
15 changes: 6 additions & 9 deletions pkg/skaffold/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ type skaffoldWriter struct {
}

func (s skaffoldWriter) Write(p []byte) (int, error) {
written := 0
if len(p) == 0 {
return 0, nil
}
if s.timestamps {
t, err := s.MainWriter.Write([]byte(time.Now().Format(timestampFormat) + " "))
if err != nil {
return t, err
if _, err := io.WriteString(s.MainWriter, time.Now().Format(timestampFormat+" ")); err != nil {
return 0, err
}

written += t
}

n, err := s.MainWriter.Write(p)
Expand All @@ -56,11 +55,9 @@ func (s skaffoldWriter) Write(p []byte) (int, error) {
return n, io.ErrShortWrite
}

written += n

s.EventWriter.Write(p)

return written, nil
return n, nil
}

func GetWriter(ctx context.Context, out io.Writer, defaultColor int, forceColors bool, timestamps bool) io.Writer {
Expand Down
10 changes: 8 additions & 2 deletions pkg/skaffold/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,17 @@ func TestWriteWithTimeStamps(t *testing.T) {
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
testutil.Run(t, test.name, func(t *testutil.T) {
var buf bytes.Buffer
out := test.writer(&buf)
Default.Fprintf(out, "testing!")
testutil.CheckDeepEqual(t, test.expectedLen, len(buf.String()))
t.CheckDeepEqual(test.expectedLen, len(buf.String()))

// Consume same number of bytes regardless of writer options.
out2 := test.writer(io.Discard)
n, err := out2.Write([]byte("testing!"))
t.CheckNoError(err)
t.CheckDeepEqual(len("testing!"), n)
})
}
}