forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_test.go
59 lines (54 loc) · 1.53 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package syslogexporter
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDeduplicateErrors(t *testing.T) {
testCases := []struct {
name string
errs []error
expected []error
}{
{
name: "nil is returned as nil",
errs: nil,
expected: nil,
},
{
name: "single error is returned as-is",
errs: []error{
errors.New("Single error"),
},
expected: []error{
errors.New("Single error"),
},
},
{
name: "duplicates are removed",
errs: []error{
errors.New("failed sending data: 502 Bad Gateway"),
errors.New("dial tcp 127.0.0.1:514: connect: connection refused"),
errors.New("failed sending data: 502 Bad Gateway"),
errors.New("dial tcp 127.0.0.1:514: connect: connection refused"),
errors.New("dial tcp 127.0.0.1:514: connect: connection refused"),
errors.New("dial tcp 127.0.0.1:514: connect: connection refused"),
errors.New("failed sending data: 504 Gateway Timeout"),
errors.New("failed sending data: 502 Bad Gateway"),
},
expected: []error{
fmt.Errorf("%w (x3)", errors.New("failed sending data: 502 Bad Gateway")),
fmt.Errorf("%w (x4)", errors.New("dial tcp 127.0.0.1:514: connect: connection refused")),
errors.New("failed sending data: 504 Gateway Timeout"),
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
assert.Equal(t, testCase.expected, deduplicateErrors(testCase.errs))
})
}
}