2020-05-30 00:34:53 +02:00
|
|
|
// Copyright The OpenTelemetry Authors
|
2024-02-29 08:05:28 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-05-30 00:34:53 +02:00
|
|
|
|
2020-11-16 19:30:54 +02:00
|
|
|
package otel
|
2020-05-30 00:34:53 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-01 21:16:03 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2020-05-30 00:34:53 +02:00
|
|
|
)
|
|
|
|
|
2023-03-01 21:16:03 +02:00
|
|
|
type testErrHandler struct {
|
|
|
|
err error
|
2020-05-30 00:34:53 +02:00
|
|
|
}
|
|
|
|
|
2023-03-01 21:16:03 +02:00
|
|
|
var _ ErrorHandler = &testErrHandler{}
|
2021-08-06 19:05:32 +02:00
|
|
|
|
2023-03-01 21:16:03 +02:00
|
|
|
func (eh *testErrHandler) Handle(err error) { eh.err = err }
|
2021-08-06 19:05:32 +02:00
|
|
|
|
2023-03-01 21:16:03 +02:00
|
|
|
func TestGlobalErrorHandler(t *testing.T) {
|
2024-04-04 22:36:34 +02:00
|
|
|
SetErrorHandler(GetErrorHandler())
|
|
|
|
assert.NotPanics(t, func() { Handle(assert.AnError) }, "Default assignment")
|
|
|
|
|
2023-03-01 21:16:03 +02:00
|
|
|
e1 := &testErrHandler{}
|
|
|
|
SetErrorHandler(e1)
|
|
|
|
Handle(assert.AnError)
|
|
|
|
assert.ErrorIs(t, e1.err, assert.AnError)
|
|
|
|
e1.err = nil
|
2021-08-06 19:05:32 +02:00
|
|
|
|
2023-03-01 21:16:03 +02:00
|
|
|
e2 := &testErrHandler{}
|
|
|
|
SetErrorHandler(e2)
|
|
|
|
GetErrorHandler().Handle(assert.AnError)
|
|
|
|
assert.ErrorIs(t, e2.err, assert.AnError)
|
2021-08-06 19:05:32 +02:00
|
|
|
}
|