(t *testing.T, collector prometheus.Collector, count int)
| 117 | } |
| 118 | |
| 119 | func collectAndSortMetrics(t *testing.T, collector prometheus.Collector, count int) []*dto.Metric { |
| 120 | ch := make(chan prometheus.Metric, count) |
| 121 | defer close(ch) |
| 122 | |
| 123 | var metrics []*dto.Metric |
| 124 | |
| 125 | collector.Collect(ch) |
| 126 | for i := 0; i < count; i++ { |
| 127 | m := <-ch |
| 128 | |
| 129 | var metric dto.Metric |
| 130 | err := m.Write(&metric) |
| 131 | require.NoError(t, err) |
| 132 | |
| 133 | metrics = append(metrics, &metric) |
| 134 | } |
| 135 | |
| 136 | // Ensure always the same order of metrics |
| 137 | sort.Slice(metrics, func(i, j int) bool { |
| 138 | return slices.IsSorted([]string{metrics[i].Label[0].GetValue(), metrics[j].Label[1].GetValue()}) |
| 139 | }) |
| 140 | return metrics |
| 141 | } |
no test coverage detected