Adjust TestRegisterWithOrGet to the present (#477)

Signed-off-by: beorn7 <beorn@soundcloud.com>
This commit is contained in:
Björn Rabenstein 2018-10-10 16:58:48 +02:00 committed by stuart nelson
parent 93edea3720
commit e5d4a249c9
1 changed files with 5 additions and 11 deletions

View File

@ -738,14 +738,8 @@ func BenchmarkHandler(b *testing.B) {
} }
} }
func TestRegisterWithOrGet(t *testing.T) { func TestAlreadyRegistered(t *testing.T) {
// Replace the default registerer just to be sure. This is bad, but this reg := prometheus.NewRegistry()
// whole test will go away once RegisterOrGet is removed.
oldRegisterer := prometheus.DefaultRegisterer
defer func() {
prometheus.DefaultRegisterer = oldRegisterer
}()
prometheus.DefaultRegisterer = prometheus.NewRegistry()
original := prometheus.NewCounterVec( original := prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "test", Name: "test",
@ -761,11 +755,11 @@ func TestRegisterWithOrGet(t *testing.T) {
[]string{"foo", "bar"}, []string{"foo", "bar"},
) )
var err error var err error
if err = prometheus.Register(original); err != nil { if err = reg.Register(original); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err = prometheus.Register(equalButNotSame); err == nil { if err = reg.Register(equalButNotSame); err == nil {
t.Fatal("expected error when registringe equal collector") t.Fatal("expected error when registering equal collector")
} }
if are, ok := err.(prometheus.AlreadyRegisteredError); ok { if are, ok := err.(prometheus.AlreadyRegisteredError); ok {
if are.ExistingCollector != original { if are.ExistingCollector != original {