2018-02-05 16:05:59 -05:00
|
|
|
package streamformatter // import "github.com/docker/docker/pkg/streamformatter"
|
2017-05-01 14:54:56 -04:00
|
|
|
|
|
|
|
import (
|
2017-08-21 17:06:56 -04:00
|
|
|
"bytes"
|
2017-05-01 14:54:56 -04:00
|
|
|
"testing"
|
|
|
|
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2017-05-01 14:54:56 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStreamWriterStdout(t *testing.T) {
|
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
content := "content"
|
|
|
|
sw := NewStdoutWriter(buffer)
|
|
|
|
size, err := sw.Write([]byte(content))
|
|
|
|
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(len(content), size))
|
2017-05-01 14:54:56 -04:00
|
|
|
|
|
|
|
expected := `{"stream":"content"}` + streamNewline
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.Equal(expected, buffer.String()))
|
2017-05-01 14:54:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStreamWriterStderr(t *testing.T) {
|
|
|
|
buffer := &bytes.Buffer{}
|
|
|
|
content := "content"
|
|
|
|
sw := NewStderrWriter(buffer)
|
|
|
|
size, err := sw.Write([]byte(content))
|
|
|
|
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(len(content), size))
|
2017-05-01 14:54:56 -04:00
|
|
|
|
|
|
|
expected := `{"stream":"\u001b[91mcontent\u001b[0m"}` + streamNewline
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.Equal(expected, buffer.String()))
|
2017-05-01 14:54:56 -04:00
|
|
|
}
|