forked from evergreen-ci/evergreen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggers_test.go
50 lines (42 loc) · 1.34 KB
/
loggers_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 evergreen
import (
"strings"
"testing"
"github.com/mongodb/grip/send"
"github.com/mongodb/grip/slogger"
. "github.com/smartystreets/goconvey/convey"
)
func TestLoggingWriter(t *testing.T) {
Convey("With a Logger", t, func() {
Convey("data written to Writer should match data appended", func() {
sender := send.MakeInternalLogger()
testLogger := &slogger.Logger{
Name: "",
Appenders: []send.Sender{sender},
}
logWriter := NewInfoLoggingWriter(testLogger)
testLogLine := "blah blah %x %fkjabsddg"
_, err := logWriter.Write([]byte(testLogLine + "\n"))
So(err, ShouldBeNil)
So(sender.Len(), ShouldEqual, 1)
So(strings.HasSuffix(sender.GetMessage().Rendered, testLogLine), ShouldBeTrue)
})
Convey("writer should cache data until a new line is sent", func() {
sender := send.MakeInternalLogger()
testLogger := &slogger.Logger{
Name: "",
Appenders: []send.Sender{sender},
}
logWriter := NewInfoLoggingWriter(testLogger)
msgs := []string{"foo bar", "bar", "foo", "baz baz baz!!!\n"}
for _, msg := range msgs {
content := []byte(msg)
n, err := logWriter.Write(content)
So(err, ShouldBeNil)
So(n, ShouldEqual, len(content))
}
So(sender.Len(), ShouldEqual, 1)
So(sender.GetMessage().Rendered, ShouldEndWith, strings.Trim(strings.Join(msgs, ""), "\n"))
})
})
}