-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsentry_core_wrapper_test.go
92 lines (70 loc) · 2.21 KB
/
sentry_core_wrapper_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
package logger
import (
"testing"
"time"
"github.com/getsentry/sentry-go"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
//go:generate mockgen -package logger -destination mock_zapcore_test.go go.uber.org/zap/zapcore Core
type SentryCoreWrapperSuite struct {
suite.Suite
ctrl *gomock.Controller
}
func (s *SentryCoreWrapperSuite) SetupTest() {
s.ctrl = gomock.NewController(s.T())
}
func (s *SentryCoreWrapperSuite) TearDownTest() {
s.ctrl.Finish()
}
func (s *SentryCoreWrapperSuite) TestNew() {
localCore := NewMockCore(s.ctrl)
wrappedCore := NewSentryCoreWrapper(localCore, sentry.CurrentHub()).(sentryCoreWrapper)
s.Equal(localCore, wrappedCore.LocalCore())
s.Equal(sentry.CurrentHub(), wrappedCore.SentryCore().hub)
}
func (s *SentryCoreWrapperSuite) TestCoreFunctions() {
localCore := NewMockCore(s.ctrl)
wrappedCore := NewSentryCoreWrapper(localCore, sentry.CurrentHub()).(sentryCoreWrapper)
testEntry := zapcore.Entry{
LoggerName: "test",
Time: time.Now(),
Level: zapcore.ErrorLevel,
Message: "testMessage",
}
fields := []zapcore.Field{
zap.Int("key", 1337),
}
s.Run("Enabled", func() {
localCore.EXPECT().Enabled(gomock.Any()).Return(true)
s.True(wrappedCore.Enabled(zapcore.InfoLevel))
})
s.Run("With", func() {
localCore.EXPECT().With(gomock.Eq(fields)).Return(localCore).Times(1)
newCore := wrappedCore.With(fields)
s.NotEqual(wrappedCore, newCore)
})
s.Run("Check", func() {
localCore.EXPECT().
Check(gomock.AssignableToTypeOf(testEntry), gomock.Any()).
DoAndReturn(func(ent zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
return ce.AddCore(ent, localCore)
})
checkedEntry := wrappedCore.Check(testEntry, nil)
s.Require().NotNil(testEntry)
s.Equal(testEntry.Message, checkedEntry.Message)
})
s.Run("Write", func() {
localCore.EXPECT().Write(gomock.Eq(testEntry), gomock.Eq(fields)).Return(nil)
s.Require().NoError(wrappedCore.Write(testEntry, fields))
})
s.Run("Sync", func() {
localCore.EXPECT().Sync().Return(nil)
s.Require().NoError(wrappedCore.Sync())
})
}
func TestSentryCoreWrapper(t *testing.T) {
suite.Run(t, new(SentryCoreWrapperSuite))
}