ceremonyclient/go-libp2p/p2p/metricshelper/registerer_test.go

33 lines
676 B
Go
Raw Normal View History

2023-08-21 03:50:38 +00:00
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")
}