(t *testing.T, vec *GaugeVec)
| 285 | } |
| 286 | |
| 287 | func testMetricVec(t *testing.T, vec *GaugeVec) { |
| 288 | vec.Reset() // Actually test Reset now! |
| 289 | |
| 290 | var pair [2]string |
| 291 | // Keep track of metrics. |
| 292 | expected := map[[2]string]int{} |
| 293 | |
| 294 | for i := 0; i < 1000; i++ { |
| 295 | pair[0], pair[1] = strconv.Itoa(i%4), strconv.Itoa(i%5) // Varying combinations multiples. |
| 296 | expected[pair]++ |
| 297 | vec.WithLabelValues(pair[0], pair[1]).Inc() |
| 298 | |
| 299 | expected[[2]string{"v1", "v2"}]++ |
| 300 | vec.WithLabelValues("v1", "v2").Inc() |
| 301 | } |
| 302 | |
| 303 | var total int |
| 304 | for _, metrics := range vec.metrics { |
| 305 | for _, metric := range metrics { |
| 306 | total++ |
| 307 | copy(pair[:], metric.values) |
| 308 | |
| 309 | var metricOut dto.Metric |
| 310 | if err := metric.metric.Write(&metricOut); err != nil { |
| 311 | t.Fatal(err) |
| 312 | } |
| 313 | actual := *metricOut.Gauge.Value |
| 314 | |
| 315 | var actualPair [2]string |
| 316 | for i, label := range metricOut.Label { |
| 317 | actualPair[i] = *label.Value |
| 318 | } |
| 319 | |
| 320 | // Test output pair against metric.values to ensure we've selected |
| 321 | // the right one. We check this to ensure the below check means |
| 322 | // anything at all. |
| 323 | if actualPair != pair { |
| 324 | t.Fatalf("unexpected pair association in metric map: %v != %v", actualPair, pair) |
| 325 | } |
| 326 | |
| 327 | if actual != float64(expected[pair]) { |
| 328 | t.Fatalf("incorrect counter value for %v: %v != %v", pair, actual, expected[pair]) |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | if total != len(expected) { |
| 334 | t.Fatalf("unexpected number of metrics: %v != %v", total, len(expected)) |
| 335 | } |
| 336 | |
| 337 | vec.Reset() |
| 338 | |
| 339 | if len(vec.metrics) > 0 { |
| 340 | t.Fatalf("reset failed") |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | func TestMetricVecWithConstraints(t *testing.T) { |
no test coverage detected