From 08271189d17eda58903dc728f4287c47183e367f Mon Sep 17 00:00:00 2001 From: Douglas Camata <159076+douglascamata@users.noreply.github.com> Date: Wed, 29 Mar 2023 11:15:51 +0200 Subject: [PATCH] Create a Between MetricValueExpectation Signed-off-by: Douglas Camata <159076+douglascamata@users.noreply.github.com> --- monitoring/metrics.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/monitoring/metrics.go b/monitoring/metrics.go index ba4b7af..7471c90 100644 --- a/monitoring/metrics.go +++ b/monitoring/metrics.go @@ -201,6 +201,17 @@ func Less(value float64) MetricValueExpectation { } } +// Between is a MetricValueExpectation function for WaitSumMetrics that returns true if given single sum is between +// the lower and upper bounds (non-inclusive, as in `lower < x < upper`). +func Between(lower, upper float64) MetricValueExpectation { + return func(sums ...float64) bool { + if len(sums) != 1 { + panic("between: expected one value") + } + return sums[0] > lower && sums[0] < upper + } +} + // EqualsAmongTwo is an isExpected function for WaitSumMetrics that returns true if first sum is equal to the second. // NOTE: Be careful on scrapes in between of process that changes two metrics. Those are // usually not atomic.