pomerium/internal/telemetry/metrics/helpers_test.go
Bobby DeSimone ba14ea246d
*: remove import path comments (#545)
- import path comments are obsoleted by the go.mod file's module statement

Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
2020-03-16 10:13:47 -07:00

38 lines
894 B
Go

package metrics
import (
"testing"
"github.com/google/go-cmp/cmp"
"go.opencensus.io/metric/metricdata"
)
func testMetricRetrieval(metrics []*metricdata.Metric, t *testing.T, labels []metricdata.LabelValue, value interface{}, name string) {
switch value.(type) {
case int64:
case float64:
case uint64:
default:
t.Errorf("Got an unexpected type for value: %T", value)
}
found := false
for _, metric := range metrics {
if metric.Descriptor.Name != name {
found = true
continue
}
gotLabels := metric.TimeSeries[0].LabelValues
gotValue := metric.TimeSeries[0].Points[0].Value
if diff := cmp.Diff(gotLabels, labels); diff != "" {
t.Errorf("Failed to find metric labels:\n%s", diff)
}
if diff := cmp.Diff(gotValue, value); diff != "" {
t.Errorf("Failed to find metric value:\n%s", diff)
}
}
if !found {
t.Errorf("Could not find metric %s", name)
}
}