-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollzap_test.go
106 lines (86 loc) · 2.66 KB
/
rollzap_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package rollzap
import (
"fmt"
"os"
"testing"
"time"
rollbar "github.com/rollbar/rollbar-go"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func newEntry(level zapcore.Level) zapcore.Entry {
return zapcore.Entry{
Level: level,
Time: time.Now(),
LoggerName: "test_logger",
Message: fmt.Sprintf("Test %s Messsage", level),
Caller: zapcore.EntryCaller{},
Stack: "No stack. Just test.",
}
}
func TestRollbarCoreLevels(t *testing.T) {
rc := NewRollbarCore(zapcore.DebugLevel)
if rc == nil {
t.Fatalf("RollbarCore not initialized")
}
if rc.minLevel != zapcore.DebugLevel {
t.Fatalf("rc.minLevel is not the correct value")
}
rc = NewRollbarCore(zapcore.ErrorLevel)
if rc == nil {
t.Fatalf("RollbarCore not initialized")
}
if rc.minLevel != zapcore.ErrorLevel {
t.Fatalf("rc.minLevel is not the correct value")
}
}
func TestNewRollbarCore(t *testing.T) {
token := os.Getenv("RC_TOKEN")
if token == "" {
t.Log("Running tests without token")
}
rollbar.SetToken(token)
rc := NewRollbarCore(zapcore.ErrorLevel)
if rc == nil {
t.Fatalf("RollbarCore not initialized")
}
if rc.minLevel != zapcore.ErrorLevel {
t.Fatalf("rc.minLevel is not the correct value")
}
coreFields := []zap.Field{zap.String("foo", "bar"), zap.String("moo", "cow")}
rc.With(coreFields)
if _, ok := rc.coreFields["foo"]; !ok {
t.Fatalf("core fields not stored")
}
if _, ok := rc.coreFields["moo"]; !ok {
t.Fatalf("core fields not stored")
}
debugEntry := newEntry(zapcore.DebugLevel)
rc.Check(debugEntry, nil) // should do more here?
if err := rc.Write(debugEntry, nil); err != nil {
t.Errorf("Error writing debug message %v", err)
}
// all of these will write, there are no checks, but in a real scenario, they work. Probably need to revisit this test
// Right now, this is just to make sure the different levels are entered into Rollbar correctly.
if err := rc.Write(newEntry(zapcore.InfoLevel), nil); err != nil {
t.Errorf("Error writing Info message %v", err)
}
if err := rc.Write(newEntry(zapcore.WarnLevel), nil); err != nil {
t.Errorf("Error writing warn message %v", err)
}
if err := rc.Write(newEntry(zapcore.ErrorLevel), nil); err != nil {
t.Errorf("Error writing error message %v", err)
}
if err := rc.Write(newEntry(zapcore.DPanicLevel), nil); err != nil {
t.Errorf("Error writing dpanic message %v", err)
}
if err := rc.Write(newEntry(zapcore.PanicLevel), nil); err != nil {
t.Errorf("Error writing panic message %v", err)
}
if err := rc.Write(newEntry(zapcore.FatalLevel), nil); err != nil {
t.Errorf("Error writing fatal message %v", err)
}
if err := rc.Sync(); err != nil {
t.Errorf("Sync failed - %v", err)
}
}