| 32 | ) |
| 33 | |
| 34 | func TestCheckedEntryIllegalReuse(t *testing.T) { |
| 35 | t.Parallel() |
| 36 | |
| 37 | var errOut bytes.Buffer |
| 38 | |
| 39 | testCore := zaptest.NewLogger(t).Core() |
| 40 | ce := testCore.Check(zapcore.Entry{ |
| 41 | Level: zapcore.InfoLevel, |
| 42 | Time: time.Now(), |
| 43 | Message: "hello", |
| 44 | }, nil) |
| 45 | ce.ErrorOutput = zapcore.AddSync(&errOut) |
| 46 | |
| 47 | // The first write should succeed. |
| 48 | ce.Write(zap.String("k", "v"), zap.Int("n", 42)) |
| 49 | assert.Empty(t, errOut.String(), "Expected no errors on first write.") |
| 50 | |
| 51 | // The second write should fail. |
| 52 | ce.Write(zap.String("foo", "bar"), zap.Int("x", 1)) |
| 53 | assert.Contains(t, errOut.String(), "Unsafe CheckedEntry re-use near Entry", |
| 54 | "Expected error logged on second write.") |
| 55 | } |