(t *testing.T, reg *prometheus.Registry, metrics []prometheus.Collector, expected int)
| 733 | } |
| 734 | |
| 735 | func assertMetrics(t *testing.T, reg *prometheus.Registry, metrics []prometheus.Collector, expected int) { |
| 736 | promMetrics, err := reg.Gather() |
| 737 | require.NoError(t, err) |
| 738 | |
| 739 | isExist := false |
| 740 | |
| 741 | for _, metricFamily := range promMetrics { |
| 742 | if metricFamily.GetName() == "cs_httpsource_hits_total" { |
| 743 | isExist = true |
| 744 | |
| 745 | assert.Len(t, metricFamily.GetMetric(), 1) |
| 746 | |
| 747 | for _, metric := range metricFamily.GetMetric() { |
| 748 | assert.InDelta(t, float64(expected), metric.GetCounter().GetValue(), 0.000001) |
| 749 | labels := metric.GetLabel() |
| 750 | assert.Len(t, labels, 4) |
| 751 | assert.Equal(t, "acquis_type", labels[0].GetName()) |
| 752 | assert.Empty(t, labels[0].GetValue()) |
| 753 | assert.Equal(t, "datasource_type", labels[1].GetName()) |
| 754 | assert.Equal(t, "http", labels[1].GetValue()) |
| 755 | assert.Equal(t, "path", labels[2].GetName()) |
| 756 | assert.Equal(t, "/test", labels[2].GetValue()) |
| 757 | assert.Equal(t, "src", labels[3].GetName()) |
| 758 | assert.Equal(t, "127.0.0.1", labels[3].GetValue()) |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | if !isExist && expected > 0 { |
| 764 | t.Fatal("expected metric cs_httpsource_hits_total not found") |
| 765 | } |
| 766 | |
| 767 | for _, metric := range metrics { |
| 768 | metric.(*prometheus.CounterVec).Reset() |
| 769 | } |
| 770 | } |
no test coverage detected
searching dependent graphs…