diff --git a/zapcore/sampler_test.go b/zapcore/sampler_test.go index 30152d957..5bcc37a34 100644 --- a/zapcore/sampler_test.go +++ b/zapcore/sampler_test.go @@ -225,8 +225,22 @@ func TestSamplerRaces(t *testing.T) { wg.Wait() } -func TestSamplerBounds(t *testing.T) { - // Prove that out-of-bounds levels don't crash. - sampler, _ := fakeSampler(DebugLevel-1, time.Minute, 2, 3) - writeSequence(sampler, 1, DebugLevel-1) +func TestSamplerUnknownLevels(t *testing.T) { + // Prove that out-of-bounds levels don't panic. + unknownLevels := []Level{ + DebugLevel - 1, + FatalLevel + 1, + } + + for _, lvl := range unknownLevels { + t.Run(lvl.String(), func(t *testing.T) { + sampler, logs := fakeSampler(lvl, time.Minute, 2, 3) + for i := 1; i < 10; i++ { + writeSequence(sampler, i, lvl) + } + + // Expect no sampling for unknown levels. + assertSequence(t, logs.TakeAll(), lvl, 1, 2, 3, 4, 5, 6, 7, 8, 9) + }) + } }