Skip to content

Commit e815c61

Browse files
authored
Merge pull request #219 from heroku/vmc-kit-test
go-kit: Add CheckCounterExists for testmetrics
2 parents c8125b8 + e7a6e52 commit e815c61

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

go-kit/metrics/testmetrics/provider.go

+18
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,24 @@ func (p *Provider) CheckNoCounter(name string, labelValues ...string) {
170170
}
171171
}
172172

173+
// CheckCounterExists checks that there is registered counter with the name
174+
// provided and value is not 0.
175+
func (p *Provider) CheckCounterExists(name string, labelValues ...string) {
176+
p.t.Helper()
177+
178+
p.Lock()
179+
defer p.Unlock()
180+
181+
k := p.keyFor(name, labelValues...)
182+
counter, ok := p.counters[k]
183+
if !ok {
184+
p.t.Fatalf("a counter named %s was not found", k)
185+
}
186+
if counter.value == 0 {
187+
p.t.Fatalf("counter %s value is 0", k)
188+
}
189+
}
190+
173191
// CheckObservationsMinMax checks that there is a histogram
174192
// with the name and that the values all fall within the min/max range.
175193
func (p *Provider) CheckObservationsMinMax(name string, min, max float64, labelValues ...string) {

0 commit comments

Comments
 (0)