-
Notifications
You must be signed in to change notification settings - Fork 21
/
basic_cmds_test.go
117 lines (98 loc) · 2.14 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package ts3
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCmdsBasic(t *testing.T) {
s := newServer(t)
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())
}()
testCmdsBasic(t, c)
}
func TestCmdsBasicSSH(t *testing.T) {
s := newServer(t, useSSH())
defer func() {
assert.NoError(t, s.Close())
}()
c, err := NewClient(s.Addr, Timeout(time.Second*2), SSH(sshClientTestConfig))
if !assert.NoError(t, err) {
return
}
defer func() {
assert.NoError(t, c.Close())
}()
testCmdsBasic(t, c)
}
func testCmdsBasic(t *testing.T, c *Client) {
t.Helper()
auth := func(t *testing.T) {
t.Helper()
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) {
t.Helper()
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) {
t.Helper()
assert.NoError(t, c.Use(1))
}
usePort := func(t *testing.T) {
t.Helper()
assert.NoError(t, c.UsePort(1024))
}
whoami := func(t *testing.T) {
t.Helper()
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)
}
}