MCPcopy
hub / github.com/prometheus/client_golang / testCurryVec

Function testCurryVec

prometheus/vec_test.go:506–701  ·  view source on GitHub ↗
(t *testing.T, vec *CounterVec)

Source from the content-addressed store, hash-verified

504}
505
506func testCurryVec(t *testing.T, vec *CounterVec) {
507 assertMetrics := func(t *testing.T) {
508 n := 0
509 for _, m := range vec.metrics {
510 n += len(m)
511 }
512 if n != 2 {
513 t.Error("expected two metrics, got", n)
514 }
515 m := &dto.Metric{}
516 c1, err := vec.GetMetricWithLabelValues("1", "2", "3")
517 if err != nil {
518 t.Fatal("unexpected error getting metric:", err)
519 }
520 c1.Write(m)
521 if want, got := 1., m.GetCounter().GetValue(); want != got {
522 t.Errorf("want %f as counter value, got %f", want, got)
523 }
524 m.Reset()
525 c2, err := vec.GetMetricWithLabelValues("11", "22", "33")
526 if err != nil {
527 t.Fatal("unexpected error getting metric:", err)
528 }
529 c2.Write(m)
530 if want, got := 1., m.GetCounter().GetValue(); want != got {
531 t.Errorf("want %f as counter value, got %f", want, got)
532 }
533 }
534
535 assertNoMetric := func(t *testing.T) {
536 if n := len(vec.metrics); n != 0 {
537 t.Error("expected no metrics, got", n)
538 }
539 }
540
541 t.Run("zero labels", func(t *testing.T) {
542 c1 := vec.MustCurryWith(nil)
543 c2 := vec.MustCurryWith(nil)
544 c1.WithLabelValues("1", "2", "3").Inc()
545 c2.With(Labels{"one": "11", "two": "22", "three": "33"}).Inc()
546 assertMetrics(t)
547 if !c1.Delete(Labels{"one": "1", "two": "2", "three": "3"}) {
548 t.Error("deletion failed")
549 }
550 if !c2.DeleteLabelValues("11", "22", "33") {
551 t.Error("deletion failed")
552 }
553 assertNoMetric(t)
554 })
555 t.Run("first label", func(t *testing.T) {
556 c1 := vec.MustCurryWith(Labels{"one": "1"})
557 c2 := vec.MustCurryWith(Labels{"one": "11"})
558 c1.WithLabelValues("2", "3").Inc()
559 c2.With(Labels{"two": "22", "three": "33"}).Inc()
560 assertMetrics(t)
561 if c1.Delete(Labels{"two": "22", "three": "33"}) {
562 t.Error("deletion unexpectedly succeeded")
563 }

Callers 3

TestCurryVecFunction · 0.85

Calls 14

RunMethod · 0.80
DeleteLabelValuesMethod · 0.80
WriteMethod · 0.65
MustCurryWithMethod · 0.65
IncMethod · 0.65
WithLabelValuesMethod · 0.65
WithMethod · 0.65
GetMetricWithMethod · 0.65
CurryWithMethod · 0.65
ErrorMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected