-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_internal_test.go
61 lines (49 loc) · 1.16 KB
/
logger_internal_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
package log
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_contextFields(t *testing.T) {
type tc struct {
name string
in context.Context
exp map[string]interface{}
}
rID := newTestUUID("45bf025d-9e46-45a4-8562-c37c4d48a9ca")
tcs := []tc{
{
name: "context with requers_id",
in: context.WithValue(context.Background(), ctxRequestIDKey, rID), //nolint:staticcheck // да ладно!
exp: map[string]interface{}{ctxRequestIDKey: rID.String()},
},
{
name: "empty context",
in: context.Background(),
exp: map[string]interface{}{},
},
{
name: "string equest id",
in: context.WithValue(context.Background(), ctxRequestIDKey, rID.String()), //nolint:staticcheck // ну хорош!
exp: map[string]interface{}{ctxRequestIDKey: rID.String()},
},
}
t.Parallel()
for _, tc := range tcs {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
out := contextFields(tc.in)
assert.Equal(t, tc.exp, out)
})
}
}
type testUUID struct {
str string
}
func (t testUUID) String() string {
return t.str
}
func newTestUUID(str string) testUUID {
return testUUID{str: str}
}