mirror of
https://github.com/genuinetools/reg.git
synced 2024-09-12 06:11:03 -04:00
35 lines
864 B
Go
35 lines
864 B
Go
package streamformatter // import "github.com/docker/docker/pkg/streamformatter"
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestStreamWriterStdout(t *testing.T) {
|
|
buffer := &bytes.Buffer{}
|
|
content := "content"
|
|
sw := NewStdoutWriter(buffer)
|
|
size, err := sw.Write([]byte(content))
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, len(content), size)
|
|
|
|
expected := `{"stream":"content"}` + streamNewline
|
|
assert.Equal(t, expected, buffer.String())
|
|
}
|
|
|
|
func TestStreamWriterStderr(t *testing.T) {
|
|
buffer := &bytes.Buffer{}
|
|
content := "content"
|
|
sw := NewStderrWriter(buffer)
|
|
size, err := sw.Write([]byte(content))
|
|
|
|
require.NoError(t, err)
|
|
assert.Equal(t, len(content), size)
|
|
|
|
expected := `{"stream":"\u001b[91mcontent\u001b[0m"}` + streamNewline
|
|
assert.Equal(t, expected, buffer.String())
|
|
}
|