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

Function TestWrite_Sync

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

Source from the content-addressed store, hash-verified

158}
159
160func TestWrite_Sync(t *testing.T) {
161 t.Parallel()
162
163 core, observed := observer.New(zap.InfoLevel)
164
165 w := Writer{
166 Log: zap.New(core),
167 Level: zap.InfoLevel,
168 }
169
170 io.WriteString(&w, "foo")
171 io.WriteString(&w, "bar")
172
173 t.Run("no sync", func(t *testing.T) {
174 assert.Zero(t, observed.Len(), "Expected no logs yet")
175 })
176
177 t.Run("sync", func(t *testing.T) {
178 defer observed.TakeAll()
179
180 require.NoError(t, w.Sync(), "Sync must not fail")
181
182 assert.Equal(t, []observer.LoggedEntry{
183 {Entry: zapcore.Entry{Message: "foobar"}, Context: []zapcore.Field{}},
184 }, observed.AllUntimed(), "Log messages did not match")
185 })
186
187 t.Run("sync on empty", func(t *testing.T) {
188 require.NoError(t, w.Sync(), "Sync must not fail")
189 assert.Zero(t, observed.Len(), "Expected no logs yet")
190 })
191}
192
193func BenchmarkWriter(b *testing.B) {
194 tests := []struct {

Callers

nothing calls this directly

Calls 7

SyncMethod · 0.95
NewFunction · 0.92
NewFunction · 0.92
WriteStringMethod · 0.80
TakeAllMethod · 0.80
AllUntimedMethod · 0.80
LenMethod · 0.45

Tested by

no test coverage detected