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

Function TestConsoleEncodeEntry

zapcore/console_encoder_test.go:40–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestConsoleEncodeEntry(t *testing.T) {
41 tests := []struct {
42 desc string
43 expected string
44 ent Entry
45 fields []Field
46 }{
47 {
48 desc: "info no fields",
49 expected: "2018-06-19T16:33:42Z\tinfo\tbob\tlob law\n",
50 ent: Entry{
51 Level: InfoLevel,
52 Time: time.Date(2018, 6, 19, 16, 33, 42, 99, time.UTC),
53 LoggerName: "bob",
54 Message: "lob law",
55 },
56 },
57 {
58 desc: "zero_time_omitted",
59 expected: "info\tname\tmessage\n",
60 ent: Entry{
61 Level: InfoLevel,
62 Time: time.Time{},
63 LoggerName: "name",
64 Message: "message",
65 },
66 },
67 }
68
69 cfg := testEncoderConfig()
70 cfg.EncodeTime = RFC3339TimeEncoder
71 enc := NewConsoleEncoder(cfg)
72
73 for _, tt := range tests {
74 t.Run(tt.desc, func(t *testing.T) {
75 buf, err := enc.EncodeEntry(tt.ent, tt.fields)
76 if assert.NoError(t, err, "Unexpected console encoding error.") {
77 assert.Equal(t, tt.expected, buf.String(), "Incorrect encoded entry.")
78 }
79 buf.Free()
80 })
81 }
82}
83
84func TestConsoleSeparator(t *testing.T) {
85 tests := []struct {

Callers

nothing calls this directly

Calls 5

testEncoderConfigFunction · 0.85
NewConsoleEncoderFunction · 0.85
EncodeEntryMethod · 0.65
StringMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected