Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions prometheus/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,32 @@ func assertEqualMFs(t *testing.T, wantMF, gotMF []*dto.MetricFamily) {
}
}

func TestWrapRegistererWithConflictingLabels(t *testing.T) {
reg := NewRegistry()
wrappedReg := WrapRegistererWith(Labels{"foo": "bar"}, reg)
collector := NewGauge(GaugeOpts{
Name: "test",
Help: "help",
ConstLabels: Labels{"foo": "baz"},
})

err := wrappedReg.Register(collector)
if err == nil {
t.Fatal("expected registration to fail")
}
if want := `attempted wrapping with already existing label name "foo"`; !strings.Contains(err.Error(), want) {
t.Fatalf("unexpected registration error: %v", err)
}

gathered, err := reg.Gather()
if err != nil {
t.Fatalf("gathering failed after rejected registration: %v", err)
}
if len(gathered) != 0 {
t.Fatalf("expected no metric families after rejected registration, got %d", len(gathered))
}
}

func TestNil(t *testing.T) {
// A wrapped nil registerer should be treated as a no-op, and not panic.
c := NewCounter(CounterOpts{Name: "test"})
Expand Down
Loading