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

Function TestLevelSampler

sampler_test.go:139–182  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

137}
138
139func TestLevelSampler(t *testing.T) {
140 // Create mock samplers that return true for specific levels
141 traceSampler := &BasicSampler{N: 1} // Always sample
142 debugSampler := &BasicSampler{N: 0} // Never sample
143 infoSampler := &BasicSampler{N: 1} // Always sample
144 warnSampler := &BasicSampler{N: 0} // Never sample
145 errorSampler := &BasicSampler{N: 1} // Always sample
146
147 sampler := LevelSampler{
148 TraceSampler: traceSampler,
149 DebugSampler: debugSampler,
150 InfoSampler: infoSampler,
151 WarnSampler: warnSampler,
152 ErrorSampler: errorSampler,
153 }
154
155 // Test each level
156 if !sampler.Sample(TraceLevel) {
157 t.Error("TraceLevel should be sampled")
158 }
159 if sampler.Sample(DebugLevel) {
160 t.Error("DebugLevel should not be sampled")
161 }
162 if !sampler.Sample(InfoLevel) {
163 t.Error("InfoLevel should be sampled")
164 }
165 if sampler.Sample(WarnLevel) {
166 t.Error("WarnLevel should not be sampled")
167 }
168 if !sampler.Sample(ErrorLevel) {
169 t.Error("ErrorLevel should be sampled")
170 }
171
172 // Test levels not covered by the LevelSampler sampler (FatalLevel, PanicLevel, NoLevel) - should return true
173 if !sampler.Sample(FatalLevel) {
174 t.Error("FatalLevel should return true when no sampler is set")
175 }
176 if !sampler.Sample(PanicLevel) {
177 t.Error("PanicLevel should return true when no sampler is set")
178 }
179 if !sampler.Sample(NoLevel) {
180 t.Error("NoLevel should return true when no sampler is set")
181 }
182}

Callers

nothing calls this directly

Calls 2

SampleMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…