-
Notifications
You must be signed in to change notification settings - Fork 1
/
readers_test.go
50 lines (42 loc) · 1.27 KB
/
readers_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
package logging
import (
"io"
"strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestLogReader(t *testing.T) {
logContent := `
I0101 00:00:00.000Z std_logger_test.go:00 (Flow=f1): Creating 20 blocks
I0101 00:00:00.000Z std_logger_test.go:00 (Flow=f1): Here's some JSON:
{
"A": "some val",
"B": "other val"
}
Err:<nil>
I0101 00:00:00.000Z std_logger_test.go:00 (Block=addFoo): Computing 5 things
`[1:]
Convey("LogReader should read each log message.", t, func() {
r := NewLogReader(strings.NewReader(logContent))
entry, err := r.Next()
So(err, ShouldBeNil)
So(entry.header, ShouldEqual, "I0101 00:00:00.000Z std_logger_test.go:00 (Flow=f1): ")
So(entry.msg, ShouldEqual, "Creating 20 blocks")
entry, err = r.Next()
So(err, ShouldBeNil)
So(entry.header, ShouldEqual, "I0101 00:00:00.000Z std_logger_test.go:00 (Flow=f1): ")
// Note that the continuation prefix is removed.
So(entry.msg, ShouldEqual, `Here's some JSON:
{
"A": "some val",
"B": "other val"
}
Err:<nil>`)
entry, err = r.Next()
So(err, ShouldBeNil)
So(entry.header, ShouldEqual, "I0101 00:00:00.000Z std_logger_test.go:00 (Block=addFoo): ")
So(entry.msg, ShouldEqual, "Computing 5 things")
entry, err = r.Next()
So(err, ShouldEqual, io.EOF)
})
}