forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrorset_test.go
87 lines (79 loc) · 1.83 KB
/
errorset_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package resiliency_test
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/cilium/cilium/pkg/resiliency"
)
func TestErrorJoin(t *testing.T) {
uu := map[string]struct {
errs []error
total int
e string
}{
"none": {},
"nils": {
errs: []error{nil, nil},
},
"plain": {
errs: []error{errors.New("e1"), errors.New("e2"), errors.New("e3")},
total: 3,
e: "test (3/3) failed\ne1\ne2\ne3",
},
"dups": {
errs: []error{errors.New("e1"), errors.New("e2"), errors.New("e1")},
total: 3,
e: "test (2/3) failed\ne1\ne2",
},
"mix": {
errs: []error{errors.New("e1"), errors.New("e2"), errors.New("e1"), nil, errors.New("e2")},
total: 5,
e: "test (2/5) failed\ne1\ne2",
},
}
for k := range uu {
u := uu[k]
t.Run(k, func(t *testing.T) {
es := resiliency.NewErrorSet("test", len(u.errs))
es.Add(u.errs...)
if es.Error() != nil {
assert.Equal(t, u.e, errors.Join(es.Error()).Error())
}
})
}
}
func TestErrorSetAdd(t *testing.T) {
uu := map[string]struct {
errs []error
e string
}{
"none": {},
"nils": {
errs: []error{nil, nil},
},
"plain": {
errs: []error{errors.New("e1"), errors.New("e2"), errors.New("e3")},
e: "test (3/3) failed\ne1\ne2\ne3",
},
"dups": {
errs: []error{errors.New("e1"), errors.New("e2"), errors.New("e1")},
e: "test (2/3) failed\ne1\ne2",
},
"mix": {
errs: []error{errors.New("e1"), errors.New("e2"), errors.New("e1"), nil, errors.New("e2")},
e: "test (2/5) failed\ne1\ne2",
},
}
for k := range uu {
u := uu[k]
t.Run(k, func(t *testing.T) {
es := resiliency.NewErrorSet("test", len(u.errs))
es.Add(u.errs...)
if es.Error() != nil {
assert.Equal(t, u.e, es.Error().Error())
}
})
}
}