MCPcopy
hub / github.com/uber-go/zap / TestLoggedEntryContextMap

Function TestLoggedEntryContextMap

zaptest/observer/logged_entry_test.go:32–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestLoggedEntryContextMap(t *testing.T) {
33 tests := []struct {
34 msg string
35 fields []zapcore.Field
36 want map[string]interface{}
37 }{
38 {
39 msg: "no fields",
40 fields: nil,
41 want: map[string]interface{}{},
42 },
43 {
44 msg: "simple",
45 fields: []zapcore.Field{
46 zap.String("k1", "v"),
47 zap.Int64("k2", 10),
48 },
49 want: map[string]interface{}{
50 "k1": "v",
51 "k2": int64(10),
52 },
53 },
54 {
55 msg: "overwrite",
56 fields: []zapcore.Field{
57 zap.String("k1", "v1"),
58 zap.String("k1", "v2"),
59 },
60 want: map[string]interface{}{
61 "k1": "v2",
62 },
63 },
64 {
65 msg: "nested",
66 fields: []zapcore.Field{
67 zap.String("k1", "v1"),
68 zap.Namespace("nested"),
69 zap.String("k2", "v2"),
70 },
71 want: map[string]interface{}{
72 "k1": "v1",
73 "nested": map[string]interface{}{
74 "k2": "v2",
75 },
76 },
77 },
78 }
79
80 for _, tt := range tests {
81 t.Run(tt.msg, func(t *testing.T) {
82 entry := LoggedEntry{
83 Context: tt.fields,
84 }
85 assert.Equal(t, tt.want, entry.ContextMap())
86 })
87 }
88}

Callers

nothing calls this directly

Calls 4

ContextMapMethod · 0.95
StringFunction · 0.92
Int64Function · 0.92
NamespaceFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…