summaryrefslogtreecommitdiff
path: root/error_buffer_test.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-23 17:06:07 +0300
committerWolfy-J <[email protected]>2018-06-23 17:06:07 +0300
commit80bd89f91fd0055579717f3cc65b39176eb09000 (patch)
tree223e1980e580137b0b937cf6d8464aa59cc8733e /error_buffer_test.go
parentddf2ce2ca7d90d6cddf7d49e973ea4ec17f8477a (diff)
realtime error handling and displaying
Diffstat (limited to 'error_buffer_test.go')
-rw-r--r--error_buffer_test.go46
1 files changed, 38 insertions, 8 deletions
diff --git a/error_buffer_test.go b/error_buffer_test.go
index aa6a17f2..2bf98915 100644
--- a/error_buffer_test.go
+++ b/error_buffer_test.go
@@ -1,31 +1,61 @@
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()
+
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 := &errBuffer{buffer: new(bytes.Buffer)}
+ buf := newErrBuffer()
tr := make(chan interface{})
buf.Listen(func(event int, ctx interface{}) {
assert.Equal(t, EventStderrOutput, event)
- assert.Equal(t, []byte("hello"), ctx)
+ assert.Equal(t, []byte("hello\n\n"), ctx)
close(tr)
})
- buf.Write([]byte("hello"))
+ buf.Write([]byte("hello\n\n"))
<-tr
- assert.Equal(t, 5, buf.Len())
- assert.Equal(t, buf.String(), "hello")
+
+ // messages are read
+ assert.Equal(t, 0, buf.Len())
+ assert.Equal(t, "", buf.String())
+}
+
+func TestErrBuffer_Write_Event_Separated(t *testing.T) {
+ buf := newErrBuffer()
+
+ tr := make(chan interface{})
+ buf.Listen(func(event int, ctx interface{}) {
+ assert.Equal(t, EventStderrOutput, event)
+ assert.Equal(t, []byte("hello\n\n"), ctx)
+ close(tr)
+ })
+
+ buf.Write([]byte("hel"))
+ buf.Write([]byte("lo\n\n"))
+ buf.Write([]byte("ending"))
+
+ <-tr
+ assert.Equal(t, 6, buf.Len())
+ assert.Equal(t, "ending", buf.String())
+}
+
+func TestErrBuffer_Write_Remaining(t *testing.T) {
+ buf := newErrBuffer()
+
+ buf.Write([]byte("hel"))
+
+ assert.Equal(t, 3, buf.Len())
+ assert.Equal(t, "hel", buf.String())
}