-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy patherrors_test.go
73 lines (69 loc) · 1.61 KB
/
errors_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 centrifuge_test
import (
"errors"
"strings"
"testing"
"github.com/centrifugal/centrifuge-go"
)
func TestErrors(t *testing.T) {
cases := []struct {
name string
rootError error
factory func(err error) error
}{
{
name: "SubscriptionSubscribeError",
rootError: centrifuge.ErrTimeout,
factory: func(err error) error {
return centrifuge.SubscriptionSubscribeError{Err: err}
},
},
{
name: "SubscriptionRefreshError",
rootError: centrifuge.ErrUnauthorized,
factory: func(err error) error {
return centrifuge.SubscriptionRefreshError{Err: err}
},
},
{
name: "ConfigurationError",
rootError: centrifuge.ErrClientClosed,
factory: func(err error) error {
return centrifuge.ConfigurationError{Err: err}
},
},
{
name: "RefreshError",
rootError: centrifuge.ErrClientClosed,
factory: func(err error) error {
return centrifuge.RefreshError{Err: err}
},
},
{
name: "ConnectError",
rootError: centrifuge.ErrClientClosed,
factory: func(err error) error {
return centrifuge.ConnectError{Err: err}
},
},
{
name: "TransportError",
rootError: centrifuge.ErrClientClosed,
factory: func(err error) error {
return centrifuge.TransportError{Err: err}
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
err := c.factory(c.rootError)
parts := strings.Split(err.Error(), ": ")
if parts[1] != c.rootError.Error() {
t.Errorf("unexpected error string: %v", err)
}
if !errors.Is(err, c.rootError) {
t.Errorf("expected root error to be wrapped")
}
})
}
}