(t *testing.T)
| 158 | } |
| 159 | |
| 160 | func 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 | |
| 193 | func BenchmarkWriter(b *testing.B) { |
| 194 | tests := []struct { |
nothing calls this directly
no test coverage detected