mirror of
https://github.com/genuinetools/reg.git
synced 2024-08-21 14:20:23 -04:00
36 lines
880 B
Go
36 lines
880 B
Go
package streamformatter // import "github.com/docker/docker/pkg/streamformatter"
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"gotest.tools/assert"
|
|
is "gotest.tools/assert/cmp"
|
|
)
|
|
|
|
func TestStreamWriterStdout(t *testing.T) {
|
|
buffer := &bytes.Buffer{}
|
|
content := "content"
|
|
sw := NewStdoutWriter(buffer)
|
|
size, err := sw.Write([]byte(content))
|
|
|
|
assert.NilError(t, err)
|
|
assert.Check(t, is.Equal(len(content), size))
|
|
|
|
expected := `{"stream":"content"}` + streamNewline
|
|
assert.Check(t, is.Equal(expected, buffer.String()))
|
|
}
|
|
|
|
func TestStreamWriterStderr(t *testing.T) {
|
|
buffer := &bytes.Buffer{}
|
|
content := "content"
|
|
sw := NewStderrWriter(buffer)
|
|
size, err := sw.Write([]byte(content))
|
|
|
|
assert.NilError(t, err)
|
|
assert.Check(t, is.Equal(len(content), size))
|
|
|
|
expected := `{"stream":"\u001b[91mcontent\u001b[0m"}` + streamNewline
|
|
assert.Check(t, is.Equal(expected, buffer.String()))
|
|
}
|