-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogger_test.go
More file actions
38 lines (28 loc) · 806 Bytes
/
logger_test.go
File metadata and controls
38 lines (28 loc) · 806 Bytes
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
package context
import (
"testing"
"github.com/apex/log"
"github.com/apex/log/handlers/memory"
)
const testMsg = "Test message"
func TestLogger(t *testing.T) {
memLog := &log.Logger{
Handler: memory.New(),
}
memLog.Debug(testMsg)
ctx := WithLogger(Background(), memLog)
rmemLog := GetLogger(ctx)
if rmemLog != memLog {
t.Fatalf("Expected %+v logger, but got %+v", memLog, rmemLog)
}
actualHandler, ok := memLog.Handler.(*memory.Handler)
if !ok {
t.Fatalf("Unexpected handler %+v", memLog.Handler)
}
if len(actualHandler.Entries) != 1 {
t.Fatalf("Expected only one entry, but got %d", len(actualHandler.Entries))
}
if actualHandler.Entries[0].Message != testMsg {
t.Fatalf(`Wrong message in entry, expected "%s" got "%s"`, testMsg, actualHandler.Entries[0].Message)
}
}