MCPcopy
hub / github.com/rs/zerolog / TestTestWriter

Function TestTestWriter

writer_test.go:164–207  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestTestWriter(t *testing.T) {
165 tests := []struct {
166 name string
167 write []byte
168 want []byte
169 }{{
170 name: "newline",
171 write: []byte("newline\n"),
172 want: []byte("newline"),
173 }, {
174 name: "oneline",
175 write: []byte("oneline"),
176 want: []byte("oneline"),
177 }, {
178 name: "twoline",
179 write: []byte("twoline\n\n"),
180 want: []byte("twoline"),
181 }}
182
183 for _, tt := range tests {
184 t.Run(tt.name, func(t *testing.T) {
185 tb := &testingLog{TB: t} // Capture TB log buffer.
186 w := TestWriter{T: tb}
187
188 n, err := w.Write(tt.write)
189 if err != nil {
190 t.Error(err)
191 }
192 if n != len(tt.write) {
193 t.Errorf("Expected %d write length but got %d", len(tt.write), n)
194 }
195 p := tb.buf.Bytes()
196 if !bytes.Equal(tt.want, p) {
197 t.Errorf("Expected %q, got %q.", tt.want, p)
198 }
199
200 log := New(NewConsoleWriter(ConsoleTestWriter(t)))
201 log.Info().Str("name", tt.name).Msg("Success!")
202
203 tb.buf.Reset()
204 })
205 }
206
207}
208
209func TestFilteredLevelWriter(t *testing.T) {
210 buf := bytes.Buffer{}

Callers

nothing calls this directly

Calls 11

WriteMethod · 0.95
NewFunction · 0.85
NewConsoleWriterFunction · 0.85
ConsoleTestWriterFunction · 0.85
MsgMethod · 0.80
ResetMethod · 0.80
RunMethod · 0.65
InfoMethod · 0.65
ErrorMethod · 0.45
BytesMethod · 0.45
StrMethod · 0.45

Tested by

no test coverage detected