// Copyright 2024 Matthew Rich . All rights reserved. package containerlog import ( "github.com/stretchr/testify/assert" "testing" "bytes" "io" ) func TestStreamReader(t *testing.T) { var logs bytes.Buffer logs.Write(StreamStdout.Log("stdout log message")) logs.Write(StreamStderr.Log("stderr log message")) logs.Write(StreamStdout.Log("stdout log message - line 2")) logs.Write(StreamStderr.Log("stderr log message - line 2")) logs.Write(StreamStderr.Log("stderr log message - line 3")) sr := NewStreamReader(&logs) outpipe := sr.StdoutPipe() errpipe := sr.StderrPipe() var message []byte = make([]byte, 20) n, ee := errpipe.Read(message) assert.Nil(t, ee) assert.Equal(t, 20, n) assert.Equal(t, "stderr log messagest", string(message)) ov, oe := io.ReadAll(outpipe) assert.Nil(t, oe) assert.Equal(t, "stdout log messagestdout log message - line 2", string(ov)) }