diff --git a/prometheus/testutil/testutil.go b/prometheus/testutil/testutil.go index b1cfdbd9d..855838717 100644 --- a/prometheus/testutil/testutil.go +++ b/prometheus/testutil/testutil.go @@ -255,16 +255,9 @@ func compareMetricFamilies(got, expected []*dto.MetricFamily, metricNames ...str got = filterMetrics(got, metricNames) expected = filterMetrics(expected, metricNames) if len(metricNames) > len(got) { - h := make(map[string]struct{}) - for _, mf := range got { - if mf == nil { - continue - } - h[mf.GetName()] = struct{}{} - } var missingMetricNames []string for _, name := range metricNames { - if _, ok := h[name]; !ok { + if _, ok := hasMetricByName(got,name); !ok { missingMetricNames = append(missingMetricNames, name) } } diff --git a/prometheus/testutil/testutil_test.go b/prometheus/testutil/testutil_test.go index bfe0f2c96..00d5de8f8 100644 --- a/prometheus/testutil/testutil_test.go +++ b/prometheus/testutil/testutil_test.go @@ -335,8 +335,8 @@ func TestScrapeAndCompare(t *testing.T) { scenarios := map[string]struct { want string metricNames []string - errPrefix string - fail bool + // expectedErrPrefix if empty, means no fail is expected for the comparison. + expectedErrPrefix string }{ "empty metric Names": { want: `