prometheus-paperless-exporter/internal/testutil/metrics.go
Michael Hanselmann f2cc188833
Some checks failed
Run tests / test (push) Has been cancelled
Release / release (push) Has been cancelled
Initial commit
Signed-off-by: Michael Hanselmann <public@hansmi.ch>
2023-07-03 00:16:08 +02:00

34 lines
592 B
Go

package testutil
import (
"strings"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
)
func CollectAndCompare(t *testing.T, c prometheus.Collector, want string, metricNames ...string) {
t.Helper()
if err := testutil.CollectAndCompare(c, strings.NewReader(want), metricNames...); err != nil {
t.Error(err)
}
}
func DiscardMetrics(t *testing.T) chan<- prometheus.Metric {
t.Helper()
ch := make(chan prometheus.Metric)
t.Cleanup(func() {
close(ch)
})
go func() {
for range ch {
}
}()
return ch
}