ceremonyclient/go-libp2p/p2p/metricshelper/registerer_test.go
2023-08-20 23:07:43 -05:00

33 lines
676 B
Go

package metricshelper
import (
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
)
func TestRegisterCollectors(t *testing.T) {
reg := prometheus.NewRegistry()
c1 := prometheus.NewCounter(
prometheus.CounterOpts{
Name: "counter",
},
)
c2 := prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "test",
Name: "gauge",
},
)
// c3 == c1
c3 := prometheus.NewCounter(
prometheus.CounterOpts{
Name: "counter",
},
)
require.NotPanics(t, func() { RegisterCollectors(reg, c1, c2) })
require.NotPanics(t, func() { RegisterCollectors(reg, c3) }, "should not panic on duplicate registration")
}