This repository has been archived by the owner on Oct 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ignore_list_test.go
73 lines (62 loc) · 1.54 KB
/
ignore_list_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
package maperr_test
import (
"errors"
"testing"
"go.uber.org/multierr"
"github.com/iZettle/maperr/v4"
)
func Test_IgnoreListMapper_Map_WithMultiErr(t *testing.T) {
errLayerOneFailed := errors.New("layer 1 failed")
errTextLayerTwoFailed := "bar %d"
tests := []struct {
name string
given error
}{
{
name: "error ignored",
given: errLayerOneFailed,
},
{
name: "formatted error ignored",
given: maperr.Errorf(errTextLayerTwoFailed, "foo"),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
// append the error at the end of a series of errors to ensure
// that we are comparing against the lastErr error
chainOfErrors := maperr.Combine(
errors.New("first"),
errors.New("second"),
errors.New("third"),
test.given,
)
ignoreMapper := maperr.NewIgnoreListMapper().
Append(errLayerOneFailed).
Appendf(errTextLayerTwoFailed)
mappedErr := maperr.NewMultiErr(ignoreMapper).
Mapped(chainOfErrors, errors.New("default error"))
if mappedErr != nil {
t.Fatalf("expected nil got err %s", mappedErr.Error())
}
})
}
}
func TestMap_IgnoreListMapper_FindAnyErrorInChain(t *testing.T) {
errSecond := errors.New("second error")
errChain := multierr.Combine(
errors.New("first error"),
errSecond,
errors.New("third error"),
errors.New("forth error"),
errors.New("fifth error"),
)
mappedErr := maperr.NewMultiErr(
maperr.
NewIgnoreListMapper().
Append(errSecond),
).Mapped(errChain, nil)
if mappedErr != nil {
t.Fatal("expected nil got err")
}
}