-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
53 lines (41 loc) · 1.28 KB
/
client_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
package rcon
import (
"encoding/binary"
"testing"
"github.com/refractorgscm/rcon2/fakeserver"
"github.com/stretchr/testify/assert"
)
func TestNewClient(t *testing.T) {
client := NewClient("localhost", 1234, "suPerSecure123")
assert.Equal(t, "localhost", client.config.Host)
assert.Equal(t, uint16(1234), client.config.Port)
assert.Equal(t, "suPerSecure123", client.config.Password)
}
func TestNewClientFromConfig(t *testing.T) {
config := &Config{
Host: "localhost",
Port: 1234,
Password: "suPerSecure123",
}
client := NewClientFromConfig(config)
assert.Equal(t, "localhost", client.config.Host)
assert.Equal(t, uint16(1234), client.config.Port)
assert.Equal(t, "suPerSecure123", client.config.Password)
}
func TestClient_Connect(t *testing.T) {
fakeServer := fakeserver.New(9898, binary.LittleEndian)
go fakeServer.Listen()
client := NewClient("localhost", 9898, "suPerSecure123")
err := client.Connect()
assert.Nil(t, err)
}
func TestClient_RunCommand(t *testing.T) {
fakeServer := fakeserver.New(9899, binary.LittleEndian)
go fakeServer.Listen()
client := NewClient("localhost", 9899, "suPerSecure123")
err := client.Connect()
assert.Nil(t, err)
res, err := client.RunCommand("help")
assert.Nil(t, err)
assert.Equal(t, "firstplayer\notherplayer\nlastplayer", res)
}