-
Notifications
You must be signed in to change notification settings - Fork 0
/
xwis_test.go
139 lines (119 loc) · 2.57 KB
/
xwis_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package xwis
import (
"context"
"log"
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
func init() {
if false {
DebugLog = log.New(os.Stderr, "", 0)
}
}
func TestHost(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
const servUser = "testserv"
info := GameInfo{
Access: AccessOpen,
Resolution: Res640x480,
Players: 3,
MaxPlayers: 32,
Map: "headache",
Name: "Test Server",
MapType: MapTypeChat,
FragLimit: 5,
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
cli, err := NewClient(ctx, servUser, servUser)
require.NoError(t, err)
defer cli.Close()
err = cli.HostGame(ctx, info)
require.NoError(t, err)
}
func TestRegister(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
const servUser = "testserv"
info := GameInfo{
Access: AccessOpen,
Resolution: Res640x480,
Players: 4,
MaxPlayers: 32,
Map: "headache",
Name: "Test Server",
MapType: MapTypeChat,
FragLimit: 5,
}
info.setDefaults()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
cli, err := NewClient(ctx, servUser, servUser)
require.NoError(t, err)
defer cli.Close()
g, err := cli.RegisterGame(ctx, info)
require.NoError(t, err)
defer g.Close()
assertGame := func() {
list, err := cli.ListRooms(ctx)
require.NoError(t, err)
found := false
for _, r := range list {
if r.Game == nil {
continue
}
if r.Game.Name == info.Name {
require.NotEmpty(t, r.Game.Addr)
info.Addr = r.Game.Addr
require.Equal(t, info, *r.Game)
found = true
break
}
}
require.True(t, found)
}
assertGame()
info.Name += " 1"
info.Map += "1"
info.Players += 2
err = g.Update(ctx, info)
require.NoError(t, err)
assertGame()
}
func TestList(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
cli, err := NewClient(ctx, "", "")
require.NoError(t, err)
defer cli.Close()
list, err := cli.ListRooms(ctx)
require.NoError(t, err)
require.NotEmpty(t, list)
for _, r := range list {
if r.Game != nil {
t.Logf("%q - %q - %s", r.ID, r.Name, r.Game.Addr)
} else {
t.Logf("%q - %q", r.ID, r.Name)
}
}
}
func TestListLobbyServers(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
list, err := ListLobbyServers(ctx)
require.NoError(t, err)
require.Equal(t, []LobbyServer{
{Addr: "xwis.net:4000", Name: "XWIS"},
}, list)
}