-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry_builder_test.go
78 lines (76 loc) · 1.96 KB
/
entry_builder_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
67
68
69
70
71
72
73
74
75
76
77
78
package tower
import (
"context"
"testing"
"time"
)
func TestEntryBuilder(t *testing.T) {
tow := NewTower(Service{})
b := tow.NewEntry("foo")
if b == nil {
t.Fatal("Expected entry builder to be non-nil")
}
e := b.(*entryBuilder)
if e.code != 0 {
t.Errorf("Expected entry builder code to be 0, got %d", e.code)
}
if e.level != InfoLevel {
t.Errorf("Expected entry builder level to be InfoLevel, got %s", e.level)
}
if e.caller == nil {
t.Errorf("Expected entry builder caller to be non-nil")
}
if e.message != "foo" {
t.Errorf("Expected entry builder message to be foo, got %s", e.message)
}
b.Code(1000)
if e.code != 1000 {
t.Errorf("Expected entry builder code to be 1000, got %d", e.code)
}
b.Caller(GetCaller(1))
if e.caller == nil {
t.Errorf("Expected entry builder caller to be non-nil")
}
b.Context(F{"foo": "bar"})
if len(e.context) != 1 {
t.Errorf("Expected entry builder context to be 1, got %d", len(e.context))
}
b.Key("foo")
if e.key != "foo" {
t.Errorf("Expected entry builder key to be foo, got %s", e.key)
}
b.Message("baz")
if e.message != "baz" {
t.Errorf("Expected entry builder message to be baz, got %s", e.message)
}
b.Message("baz %s", "qux")
if e.message != "baz qux" {
t.Errorf("Expected entry builder message to be baz qux, got %s", e.message)
}
now := time.Now()
b.Time(now)
if !e.time.Equal(now) {
t.Errorf("Expected entry builder time to be %s, got %s", now, e.time)
}
b.Level(ErrorLevel)
if e.level != ErrorLevel {
t.Errorf("Expected entry builder level to be ErrorLevel, got %s", e.level)
}
m := newMockMessenger(1)
tow.RegisterMessenger(m)
b.Notify(context.Background())
err := m.Wait(context.Background())
if err != nil {
t.Fatalf("Expected no error, got %s", err)
}
if !m.called {
t.Errorf("Expected messenger to be called")
}
l := newMockLogger()
tow.SetLogger(l)
b.Log(context.Background())
if !l.called {
t.Errorf("Expected logger to be called")
}
_ = b.Freeze().(EntryNode)
}