-
Notifications
You must be signed in to change notification settings - Fork 3
/
context_test.go
51 lines (38 loc) · 1.07 KB
/
context_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
package logger
import (
"context"
"testing"
"github.com/getsentry/sentry-go"
"github.com/stretchr/testify/suite"
"go.uber.org/zap"
)
type TestContextHelpersSuite struct {
suite.Suite
}
func (s *TestContextHelpersSuite) TestRequestIDDefault() {
s.Equal("", RequestID(context.TODO()))
}
func (s *TestContextHelpersSuite) TestRequestIDStoring() {
requestID := "request_id"
ctx := WithRequestID(context.Background(), requestID)
s.Equal(requestID, RequestID(ctx))
}
func (s *TestContextHelpersSuite) TestHubDefault() {
s.Equal(sentry.CurrentHub(), Hub(context.TODO()))
}
func (s *TestContextHelpersSuite) TestHubStoring() {
hub := sentry.CurrentHub().Clone()
ctx := WithHub(context.Background(), hub)
s.Equal(hub, Hub(ctx))
}
func (s *TestContextHelpersSuite) TestLoggerDefault() {
s.Equal(zap.NewNop(), Ctx(context.TODO()))
}
func (s *TestContextHelpersSuite) TestLoggerStoring() {
logger := zap.NewExample()
ctx := WithLogger(context.Background(), logger)
s.Equal(logger, Ctx(ctx))
}
func TestContextHelpers(t *testing.T) {
suite.Run(t, new(TestContextHelpersSuite))
}