summaryrefslogtreecommitdiff
path: root/error_buffer_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-23 20:45:39 +0300
committerGitHub <[email protected]>2018-06-23 20:45:39 +0300
commit2ecba8ab4109108170433862f6d4a29abaac65d8 (patch)
tree36cfe76e67998f414d7efb00f1a7c030bbfbcfad /error_buffer_test.go
parent14a54572d7a3754aeb81d3dc9949276b7fff04fe (diff)
parent18201f5f6af71fad14bbfc93eec1654b2f8fa585 (diff)
Merge pull request #22 from spiral/feature/stderr
Feature/stderr
Diffstat (limited to 'error_buffer_test.go')
-rw-r--r--error_buffer_test.go57
1 files changed, 54 insertions, 3 deletions
diff --git a/error_buffer_test.go b/error_buffer_test.go
index afbc80e2..09ea4f03 100644
--- a/error_buffer_test.go
+++ b/error_buffer_test.go
@@ -1,14 +1,65 @@
package roadrunner
import (
- "bytes"
"github.com/stretchr/testify/assert"
"testing"
)
func TestErrBuffer_Write_Len(t *testing.T) {
- buf := &errBuffer{buffer: new(bytes.Buffer)}
+ buf := newErrBuffer()
+ defer buf.Close()
+
buf.Write([]byte("hello"))
assert.Equal(t, 5, buf.Len())
- assert.Equal(t, buf.String(), "hello")
+ assert.Equal(t, "hello", buf.String())
+}
+
+func TestErrBuffer_Write_Event(t *testing.T) {
+ buf := newErrBuffer()
+ defer buf.Close()
+
+ tr := make(chan interface{})
+ buf.Listen(func(event int, ctx interface{}) {
+ assert.Equal(t, EventStderrOutput, event)
+ assert.Equal(t, []byte("hello\n"), ctx)
+ close(tr)
+ })
+
+ buf.Write([]byte("hello\n"))
+
+ <-tr
+
+ // messages are read
+ assert.Equal(t, 6, buf.Len())
+ assert.Equal(t, "hello\n", buf.String())
+}
+
+func TestErrBuffer_Write_Event_Separated(t *testing.T) {
+ buf := newErrBuffer()
+ defer buf.Close()
+
+ tr := make(chan interface{})
+ buf.Listen(func(event int, ctx interface{}) {
+ assert.Equal(t, EventStderrOutput, event)
+ assert.Equal(t, []byte("hello\nending"), ctx)
+ close(tr)
+ })
+
+ buf.Write([]byte("hel"))
+ buf.Write([]byte("lo\n"))
+ buf.Write([]byte("ending"))
+
+ <-tr
+ assert.Equal(t, 12, buf.Len())
+ assert.Equal(t, "hello\nending", buf.String())
+}
+
+func TestErrBuffer_Write_Remaining(t *testing.T) {
+ buf := newErrBuffer()
+ defer buf.Close()
+
+ buf.Write([]byte("hel"))
+
+ assert.Equal(t, 3, buf.Len())
+ assert.Equal(t, "hel", buf.String())
}