forked from Unity-Technologies/go-ts3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_cmds_test.go
94 lines (78 loc) · 1.71 KB
/
basic_cmds_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 ts3
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCmdsBasic(t *testing.T) {
s := newServer(t)
if s == nil {
return
}
defer func() {
assert.NoError(t, s.Close())
}()
c, err := NewClient(s.Addr, Timeout(time.Second*2))
if !assert.NoError(t, err) {
return
}
defer func() {
assert.NoError(t, c.Close())
}()
auth := func(t *testing.T) {
if err = c.Login("user", "pass"); !assert.NoError(t, err) {
return
}
if err = c.Logout(); !assert.NoError(t, err) {
return
}
}
version := func(t *testing.T) {
v, err := c.Version()
if !assert.NoError(t, err) {
return
}
assert.Equal(t, "3.0.12.2", v.Version)
assert.Equal(t, 1455547898, v.Build)
assert.Equal(t, "FreeBSD", v.Platform)
}
useID := func(t *testing.T) {
assert.NoError(t, c.Use(1))
}
usePort := func(t *testing.T) {
assert.NoError(t, c.UsePort(1024))
}
whoami := func(t *testing.T) {
info, err := c.Whoami()
if !assert.NoError(t, err) {
return
}
expected := &ConnectionInfo{
ServerStatus: "online",
ServerID: 18,
ServerUniqueIdentifier: "gNITtWtKs9+Uh3L4LKv8/YHsn5c=",
ServerPort: 9987,
ClientID: 94,
ClientChannelID: 432,
ClientName: "serveradmin from 127.0.0.1:49725",
ClientDatabaseID: 1,
ClientLoginName: "serveradmin",
ClientUniqueIdentifier: "serveradmin",
ClientOriginServerID: 0,
}
assert.Equal(t, expected, info)
}
tests := []struct {
name string
f func(t *testing.T)
}{
{"auth", auth},
{"version", version},
{"useid", useID},
{"useport", usePort},
{"whoami", whoami},
}
for _, tc := range tests {
t.Run(tc.name, tc.f)
}
}