-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcontext_test.go
More file actions
118 lines (100 loc) · 2.81 KB
/
context_test.go
File metadata and controls
118 lines (100 loc) · 2.81 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
package stackdriver
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestServiceContext_Clone(t *testing.T) {
src := &ServiceContext{
Service: "foo",
Version: "bar",
}
res := src.Clone()
assert.Equal(t, src, res)
}
func TestServiceContext_MarshalLogObject(t *testing.T) {
enc := new(ObjectEncoder)
ctx := &ServiceContext{
Service: "foo",
Version: "bar",
}
enc.On("AddString", "service", ctx.Service).Once()
enc.On("AddString", "version", ctx.Version).Once()
require.Nil(t, ctx.MarshalLogObject(enc))
enc.AssertExpectations(t)
}
func TestContext_Clone(t *testing.T) {
src := &Context{
User: "foo",
HTTPRequest: &HTTPRequest{},
ReportLocation: &ReportLocation{},
}
res := src.Clone()
assert.Equal(t, src, res)
}
func TestContext_MarshalLogObject(t *testing.T) {
enc := new(ObjectEncoder)
ctx := &Context{
User: "foo",
HTTPRequest: &HTTPRequest{},
ReportLocation: &ReportLocation{},
}
enc.On("AddString", "user", ctx.User).Once()
enc.On("AddObject", "httpRequest", ctx.HTTPRequest).Return(nil).Once()
enc.On("AddObject", "reportLocation", ctx.ReportLocation).Return(nil).Once()
require.Nil(t, ctx.MarshalLogObject(enc))
enc.AssertExpectations(t)
}
func TestHTTPRequest_Clone(t *testing.T) {
src := &HTTPRequest{
Method: "GET",
URL: "/foo",
UserAgent: "bar",
Referrer: "baz",
ResponseStatusCode: 200,
RemoteIP: "1.2.3.4",
}
res := src.Clone()
assert.Equal(t, src, res)
}
func TestHTTPRequest_MarshalLogObject(t *testing.T) {
enc := new(ObjectEncoder)
req := &HTTPRequest{
Method: "GET",
URL: "/foo",
UserAgent: "bar",
Referrer: "baz",
ResponseStatusCode: 200,
RemoteIP: "1.2.3.4",
}
enc.On("AddString", "method", req.Method).Once()
enc.On("AddString", "url", req.URL).Once()
enc.On("AddString", "userAgent", req.UserAgent).Once()
enc.On("AddString", "referrer", req.Referrer).Once()
enc.On("AddInt", "responseStatusCode", req.ResponseStatusCode).Once()
enc.On("AddString", "remoteIp", req.RemoteIP).Once()
require.Nil(t, req.MarshalLogObject(enc))
enc.AssertExpectations(t)
}
func TestReportLocation_Clone(t *testing.T) {
src := &ReportLocation{
FilePath: "foo",
FunctionName: "bar",
LineNumber: 42,
}
res := src.Clone()
assert.Equal(t, src, res)
}
func TestReportLocation_MarshalLogObject(t *testing.T) {
enc := new(ObjectEncoder)
loc := &ReportLocation{
FilePath: "foo",
FunctionName: "bar",
LineNumber: 42,
}
enc.On("AddString", "filePath", loc.FilePath).Once()
enc.On("AddString", "functionName", loc.FunctionName).Once()
enc.On("AddInt", "lineNumber", loc.LineNumber).Once()
require.Nil(t, loc.MarshalLogObject(enc))
enc.AssertExpectations(t)
}