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

Function TestWriter

zapio/writer_test.go:34–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32)
33
34func TestWriter(t *testing.T) {
35 t.Parallel()
36
37 tests := []struct {
38 desc string
39 level zapcore.Level // defaults to info
40 writes []string
41 want []zapcore.Entry
42 }{
43 {
44 desc: "simple",
45 writes: []string{
46 "foo\n",
47 "bar\n",
48 "baz\n",
49 },
50 want: []zapcore.Entry{
51 {Level: zap.InfoLevel, Message: "foo"},
52 {Level: zap.InfoLevel, Message: "bar"},
53 {Level: zap.InfoLevel, Message: "baz"},
54 },
55 },
56 {
57 desc: "level too low",
58 level: zap.DebugLevel,
59 writes: []string{
60 "foo\n",
61 "bar\n",
62 },
63 want: []zapcore.Entry{},
64 },
65 {
66 desc: "multiple newlines in a message",
67 level: zap.WarnLevel,
68 writes: []string{
69 "foo\nbar\n",
70 "baz\n",
71 "qux\nquux\n",
72 },
73 want: []zapcore.Entry{
74 {Level: zap.WarnLevel, Message: "foo"},
75 {Level: zap.WarnLevel, Message: "bar"},
76 {Level: zap.WarnLevel, Message: "baz"},
77 {Level: zap.WarnLevel, Message: "qux"},
78 {Level: zap.WarnLevel, Message: "quux"},
79 },
80 },
81 {
82 desc: "message split across multiple writes",
83 level: zap.ErrorLevel,
84 writes: []string{
85 "foo",
86 "bar\nbaz",
87 "qux",
88 },
89 want: []zapcore.Entry{
90 {Level: zap.ErrorLevel, Message: "foobar"},
91 {Level: zap.ErrorLevel, Message: "bazqux"},

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
NewFunction · 0.92
NewFunction · 0.92
WriteStringMethod · 0.80
AllUntimedMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected