-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_config_test.go
54 lines (44 loc) · 1.09 KB
/
error_config_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
package goapperrors
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_GetErrorConfig(t *testing.T) {
t.Run("found: direct mapping", func(t *testing.T) {
initConfig(okConfig)
errCfg := &ErrorConfig{
Status: 1234,
}
defer initErrorMapping(errTest1, errCfg)()
gotCfg := GetErrorConfig(errTest1)
assert.Equal(t, errCfg, gotCfg)
})
t.Run("found: indirect mapping", func(t *testing.T) {
initConfig(okConfig)
errCfg := &ErrorConfig{
Status: 1234,
}
defer initErrorMapping(errTest1, errCfg)()
e1 := Wrap(errTest1)
e2 := Wrap(e1)
e3 := fmt.Errorf("blah: %w", e2)
gotCfg := GetErrorConfig(e3)
assert.Equal(t, errCfg, gotCfg)
})
t.Run("not found", func(t *testing.T) {
initConfig(okConfig)
defer initErrorMapping(errTest1, &ErrorConfig{
Status: 1234,
})()
assert.Nil(t, GetErrorConfig(errTest2))
})
t.Run("not found: error is in multi-error", func(t *testing.T) {
initConfig(okConfig)
defer initErrorMapping(errTest1, &ErrorConfig{
Status: 1234,
})()
assert.Nil(t, GetErrorConfig(errors.Join(errTest1, errTest2)))
})
}