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