generated from devnw/oss-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors_test.go
63 lines (53 loc) · 1.06 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
package plex
import (
"net"
"testing"
)
func Test_ErrConnection(t *testing.T) {
testdata := map[string]net.Addr{
"local": &testaddr{
tcp: true,
addr: "127.0.0.1:8080",
},
"nil": nil,
}
for name, test := range testdata {
t.Run(name, func(t *testing.T) {
err := disconnected(test)
if err == nil {
t.Error("expected error")
}
if err.Error() != "disconnected" {
t.Error("expected error message to be 'disconnected'")
}
e, ok := err.(*ErrConnection)
if !ok {
t.Error("expected error to be of type ErrConnection")
}
if e.Addr != test {
t.Error("expected error to have Addr set to test")
}
})
}
}
func Test_ErrAddrMismatch(t *testing.T) {
e := &errAddrMismatch{
Expected: &testaddr{
tcp: true,
addr: "127.0.0.1",
},
Actual: &testaddr{
tcp: true,
addr: "0.0.0.0",
},
}
err := error(e)
expected := "address mismatch; expected: tcp:127.0.0.1; actual: tcp:0.0.0.0"
if err.Error() != expected {
t.Errorf(
"expected error message to be %q; got %q",
expected,
err.Error(),
)
}
}