-
Notifications
You must be signed in to change notification settings - Fork 329
/
error_test.go
63 lines (50 loc) · 1.01 KB
/
error_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
package redsync
import (
"errors"
"fmt"
"testing"
)
func TestRedisErrorIs(t *testing.T) {
cases := map[string]error{
"defined_error": ErrFailed,
"other_error": errors.New("other error"),
"wrapping_error": fmt.Errorf("wrapping: %w", ErrFailed),
}
for k, v := range cases {
t.Run(k, func(t *testing.T) {
err := RedisError{
Node: 0,
Err: v,
}
if !errors.Is(err, v) {
t.Errorf("errors.Is must be true")
}
})
}
}
func TestRedisErrorAs(t *testing.T) {
derr := dummyError{}
cases := map[string]error{
"simple_error": derr,
"wrapping_error": fmt.Errorf("wrapping: %w", derr),
}
for k, v := range cases {
t.Run(k, func(t *testing.T) {
err := RedisError{
Node: 0,
Err: v,
}
var target dummyError
if !errors.As(err, &target) {
t.Errorf("errors.As must be true")
}
if target != derr {
t.Errorf("Expected target == %q, got %q", derr, target)
}
})
}
}
type dummyError struct{}
func (err dummyError) Error() string {
return "dummy"
}