-
Notifications
You must be signed in to change notification settings - Fork 4
/
errors_test.go
46 lines (39 loc) · 966 Bytes
/
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
package netutil
import (
"errors"
"net"
"syscall"
"testing"
)
func TestErrors(t *testing.T) {
t.Parallel()
if !IsNetworkUnreachable(syscall.ENETUNREACH) {
t.Error(`!IsNetworkUnreachable(syscall.ENETUNREACH)`)
}
if IsNetworkUnreachable(errors.New("hoge")) {
t.Error(`IsNetworkUnreachable(errors.New("hoge"))`)
}
if !IsConnectionRefused(syscall.ECONNREFUSED) {
t.Error(`!IsConnectionRefused(syscall.ECONNREFUSED)`)
}
if IsConnectionRefused(errors.New("hoge")) {
t.Error(`IsConnectionRefused(errors.New("hoge"))`)
}
if !IsNoRouteToHost(syscall.EHOSTUNREACH) {
t.Error(`!IsNoRouteToHost(syscall.EHOSTUNREACH)`)
}
if IsNoRouteToHost(errors.New("hoge")) {
t.Error(`IsNoRouteToHost(errors.New("hoge"))`)
}
}
func TestConnectionRefused(t *testing.T) {
t.Parallel()
_, err := net.Dial("tcp", "localhost:38794")
if err == nil {
return
}
if !IsConnectionRefused(err) {
t.Error(`!IsConnectionRefused(err)`)
t.Log(err.Error())
}
}