Skip to content

Commit

Permalink
test: metric helper func (#455)
Browse files Browse the repository at this point in the history
new helper func to obtain a Prometheus counter value

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Feb 12, 2025
1 parent 7e89acb commit e5452d8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/test/metrics/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ func AssertMetricsCounterEquals(t *testing.T, expected int, c prometheus.Counter
}

func AssertCounterEqualsInt(t *testing.T, expected int, c prometheus.Counter) {
assert.Equal(t, expected, int(promtestutil.ToFloat64(c)))
assert.Equal(t, expected, GetCounterInt(c))
}

func GetCounterInt(c prometheus.Counter) int {
return int(promtestutil.ToFloat64(c))
}

func AssertCounterGreaterOrEqualsInt(t *testing.T, threshold int, c prometheus.Counter) {
assert.GreaterOrEqual(t, int(promtestutil.ToFloat64(c)), threshold)
assert.GreaterOrEqual(t, GetCounterInt(c), threshold)
}

func AssertMetricsGaugeEquals(t *testing.T, expected int, g prometheus.Gauge, msgAndArgs ...interface{}) {
Expand Down

0 comments on commit e5452d8

Please sign in to comment.