1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-24 20:14:40 +02:00
opentelemetry-go/handler_test.go

35 lines
720 B
Go
Raw Permalink Normal View History

2020-05-30 00:34:53 +02:00
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
2020-05-30 00:34:53 +02:00
package otel
2020-05-30 00:34:53 +02:00
import (
"testing"
"github.com/stretchr/testify/assert"
2020-05-30 00:34:53 +02:00
)
type testErrHandler struct {
err error
2020-05-30 00:34:53 +02:00
}
var _ ErrorHandler = &testErrHandler{}
func (eh *testErrHandler) Handle(err error) { eh.err = err }
func TestGlobalErrorHandler(t *testing.T) {
SetErrorHandler(GetErrorHandler())
assert.NotPanics(t, func() { Handle(assert.AnError) }, "Default assignment")
e1 := &testErrHandler{}
SetErrorHandler(e1)
Handle(assert.AnError)
assert.ErrorIs(t, e1.err, assert.AnError)
e1.err = nil
e2 := &testErrHandler{}
SetErrorHandler(e2)
GetErrorHandler().Handle(assert.AnError)
assert.ErrorIs(t, e2.err, assert.AnError)
}