github.com/OpenFlowLabs/moby@v17.12.1-ce-rc2+incompatible/pkg/streamformatter/streamwriter_test.go (about)

     1  package streamformatter
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestStreamWriterStdout(t *testing.T) {
    12  	buffer := &bytes.Buffer{}
    13  	content := "content"
    14  	sw := NewStdoutWriter(buffer)
    15  	size, err := sw.Write([]byte(content))
    16  
    17  	require.NoError(t, err)
    18  	assert.Equal(t, len(content), size)
    19  
    20  	expected := `{"stream":"content"}` + streamNewline
    21  	assert.Equal(t, expected, buffer.String())
    22  }
    23  
    24  func TestStreamWriterStderr(t *testing.T) {
    25  	buffer := &bytes.Buffer{}
    26  	content := "content"
    27  	sw := NewStderrWriter(buffer)
    28  	size, err := sw.Write([]byte(content))
    29  
    30  	require.NoError(t, err)
    31  	assert.Equal(t, len(content), size)
    32  
    33  	expected := `{"stream":"\u001b[91mcontent\u001b[0m"}` + streamNewline
    34  	assert.Equal(t, expected, buffer.String())
    35  }