forked from andrewtian/minepong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping_test.go
72 lines (55 loc) · 1.04 KB
/
ping_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
package minepong
import (
"fmt"
"net"
"sync"
"testing"
)
var testServers = map[string]string{
"desteria": "Play.NirvanaMC.com:25565",
"gotpvp": "play.gotpvp.com:25565",
}
type server struct {
name string
host string
conn net.Conn
}
func newServer(name string, host string) *server {
return &server{
name: name,
host: host,
}
}
func (s *server) connect() error {
var err error
s.conn, err = net.Dial("tcp", s.host)
if err != nil {
return err
}
return nil
}
func (s *server) disconnect() error {
return s.conn.Close()
}
func TestPing(t *testing.T) {
wg := &sync.WaitGroup{}
for name, host := range testServers {
wg.Add(1)
go func(name string, host string) {
fmt.Println("started")
svr := newServer(name, host)
if err := svr.connect(); err != nil {
panic(err)
}
fmt.Println("connected: " + svr.name)
pong, err := Ping(svr.conn, svr.host)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(svr.name, pong.Players.Online, pong.Players.Max)
wg.Done()
}(name, host)
}
wg.Wait()
}