forked from Sandertv/go-raknet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdial_test.go
94 lines (81 loc) · 1.93 KB
/
dial_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package raknet_test
import (
"net"
"strings"
"testing"
"github.com/OpenFarLands/go-raknet"
)
func TestPing(t *testing.T) {
//noinspection SpellCheckingInspection
const (
addr = "mco.mineplex.com:19132"
prefix = "MCPE"
)
data, err := raknet.Ping(addr)
if err != nil {
t.Fatalf("error pinging %v: %v", addr, err)
}
str := string(data)
if !strings.HasPrefix(str, prefix) {
t.Fatalf("ping data should have prefix %v, but got %v", prefix, str)
}
}
func TestPingWithCustomDialer(t *testing.T) {
//noinspection SpellCheckingInspection
const (
addr = "mco.mineplex.com:19132"
prefix = "MCPE"
)
localDialAddr, err := net.ResolveUDPAddr("udp", "0.0.0.0:55556")
if err != nil {
t.Fatalf("error resolving local dial address: %v", err)
}
dialer := raknet.Dialer{
UpstreamDialer: &net.Dialer{
LocalAddr: localDialAddr,
},
}
data, err := dialer.Ping(addr)
if err != nil {
t.Fatalf("error pinging %v: %v", addr, err)
}
str := string(data)
if !strings.HasPrefix(str, prefix) {
t.Fatalf("ping data should have prefix %v, but got %v", prefix, str)
}
}
func TestDial(t *testing.T) {
//noinspection SpellCheckingInspection
const (
addr = "mco.mineplex.com:19132"
)
conn, err := raknet.Dial(addr)
if err != nil {
t.Fatalf("error connecting to %v: %v", addr, err)
}
if err := conn.Close(); err != nil {
t.Fatalf("error closing connection: %v", err)
}
}
func TestDialWithCustomDialer(t *testing.T) {
//noinspection SpellCheckingInspection
const (
addr = "mco.mineplex.com:19132"
)
localDialAddr, err := net.ResolveUDPAddr("udp", "0.0.0.0:55555")
if err != nil {
t.Fatalf("error resolving local dial address: %v", err)
}
dialer := raknet.Dialer{
UpstreamDialer: &net.Dialer{
LocalAddr: localDialAddr,
},
}
conn, err := dialer.Dial(addr)
if err != nil {
t.Fatalf("error connecting to %v: %v", addr, err)
}
if err := conn.Close(); err != nil {
t.Fatalf("error closing connection: %v", err)
}
}