-
Notifications
You must be signed in to change notification settings - Fork 93
/
buffer_test.go
66 lines (52 loc) · 1.45 KB
/
buffer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package kail
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestBuffer(t *testing.T) {
source := eventSource{}
{
buffer := newBuffer(source)
events := buffer.process([]byte(""))
assert.Empty(t, events)
events = buffer.process([]byte("foo\n"))
assert.Len(t, events, 1)
assert.Equal(t, "foo", string(events[0].Log()))
}
{
buffer := newBuffer(source)
events := buffer.process([]byte("foo"))
assert.Empty(t, events)
events = buffer.process([]byte("\n"))
assert.Len(t, events, 1)
assert.Equal(t, "foo", string(events[0].Log()))
}
{
buffer := newBuffer(source)
events := buffer.process([]byte("foo\n"))
assert.Len(t, events, 1)
assert.Equal(t, "foo", string(events[0].Log()))
events = buffer.process([]byte("bar\n"))
assert.Len(t, events, 1)
assert.Equal(t, "bar", string(events[0].Log()))
}
{
buffer := newBuffer(source)
events := buffer.process([]byte("foo\nbar\n"))
assert.Len(t, events, 2)
assert.Equal(t, "foo", string(events[0].Log()))
assert.Equal(t, "bar", string(events[1].Log()))
events = buffer.process([]byte("baz\n"))
assert.Len(t, events, 1)
assert.Equal(t, "baz", string(events[0].Log()))
}
{
buffer := newBuffer(source)
events := buffer.process([]byte("foo\nbar"))
assert.Len(t, events, 1)
assert.Equal(t, "foo", string(events[0].Log()))
events = buffer.process([]byte("baz\n"))
assert.Len(t, events, 1)
assert.Equal(t, "barbaz", string(events[0].Log()))
}
}