requireCounter gathers metrics from reg, finds the named counter family, and asserts it has exactly one series with the given value and labels.
(t *testing.T, reg *prometheus.Registry, name string, wantValue float64, wantLabels map[string]string)
| 363 | // family, and asserts it has exactly one series with the given value |
| 364 | // and labels. |
| 365 | func requireCounter(t *testing.T, reg *prometheus.Registry, name string, wantValue float64, wantLabels map[string]string) { |
| 366 | t.Helper() |
| 367 | |
| 368 | families, err := reg.Gather() |
| 369 | require.NoError(t, err) |
| 370 | |
| 371 | for _, f := range families { |
| 372 | if f.GetName() != name { |
| 373 | continue |
| 374 | } |
| 375 | require.Len(t, f.GetMetric(), 1, "expected exactly one series for %s", name) |
| 376 | metric := f.GetMetric()[0] |
| 377 | assert.Equal(t, wantValue, metric.GetCounter().GetValue(), "counter value for %s", name) |
| 378 | labels := map[string]string{} |
| 379 | for _, lp := range metric.GetLabel() { |
| 380 | labels[lp.GetName()] = lp.GetValue() |
| 381 | } |
| 382 | for k, v := range wantLabels { |
| 383 | assert.Equal(t, v, labels[k], "label %s for %s", k, name) |
| 384 | } |
| 385 | return |
| 386 | } |
| 387 | t.Fatalf("metric %s not found in gathered families", name) |
| 388 | } |
| 389 | |
| 390 | func TestRecordToolError(t *testing.T) { |
| 391 | t.Parallel() |
no test coverage detected