| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package consumererror |
| 5 |
|
| 6 |
import ( |
| 7 |
"errors" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/assert" |
| 11 |
) |
| 12 |
|
| 13 |
//nolint:testifylint // Testing properties of errors, no reason to use require |
| 14 |
func TestDownstream(t *testing.T) { |
| 15 |
err1 := errors.New("test error") |
| 16 |
assert.False(t, IsDownstream(err1)) |
| 17 |
err2 := errors.New("test error 2") |
| 18 |
assert.False(t, IsDownstream(err2)) |
| 19 |
|
| 20 |
errDownstream1 := NewDownstream(err1) |
| 21 |
assert.True(t, IsDownstream(errDownstream1)) |
| 22 |
assert.Equal(t, err1.Error(), errDownstream1.Error()) |
| 23 |
assert.ErrorIs(t, errDownstream1, err1) |
| 24 |
assert.NotErrorIs(t, errDownstream1, err2) |
| 25 |
|
| 26 |
// we can access downstream wrappers through other wrappers |
| 27 |
errWrapDownstream := NewRetryableError(errDownstream1) |
| 28 |
assert.True(t, IsDownstream(errWrapDownstream)) |
| 29 |
errorStruct := new(Error) |
| 30 |
assert.ErrorAs(t, errWrapDownstream, &errorStruct) |
| 31 |
|
| 32 |
// we can access other wrappers through downstream wrappers |
| 33 |
errDownstreamWrap := NewDownstream(NewRetryableError(err1)) |
| 34 |
assert.True(t, IsDownstream(errDownstreamWrap)) |
| 35 |
assert.ErrorAs(t, errDownstreamWrap, &errorStruct) |
| 36 |
|
| 37 |
// downstream + downstream = downstream |
| 38 |
errJoin2 := errors.Join(errDownstream1, NewDownstream(err2)) |
| 39 |
assert.True(t, IsDownstream(errJoin2)) |
| 40 |
|
| 41 |
// downstream + not downstream = downstream |
| 42 |
errJoin1 := errors.Join(errDownstream1, err2) |
| 43 |
assert.True(t, IsDownstream(errJoin1)) |
| 44 |
} |