-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_test.go
101 lines (86 loc) · 2.2 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
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
package gosc
import (
"testing"
)
type testMessageReceiver struct {
received bool
}
func (t *testMessageReceiver) ReceiveMessage(_ *Message) {
t.received = true
}
func TestClient_CallMessage(t *testing.T) {
// TODO: Implement me
}
func TestClient_EmitMessage(t *testing.T) {
// TODO: Implement me
}
func TestClient_ReceiveMessage(t *testing.T) {
cli, _ := NewClient("127.0.0.1:1234")
t.Run("validPattern", func(t *testing.T) {
err := cli.ReceiveMessage("/test", &testMessageReceiver{})
if err != nil {
t.Errorf("expected no error but got: %v", err)
}
_, ok := cli.messageReceivers["/test"]
if !ok {
t.Error("expected message handler to exist in client")
}
})
t.Run("notValidPattern", func(t *testing.T) {
err := cli.ReceiveMessage("[0-9", &testMessageReceiver{})
if err == nil {
t.Error("expected error but none given")
}
})
}
func TestClient_ReceiveMessageFunc(t *testing.T) {
cli, _ := NewClient("127.0.0.1:1234")
err := cli.ReceiveMessageFunc("/test", func(msg *Message) {})
if err != nil {
t.Errorf("expected no error but got: %v", err)
}
}
func TestClient_SendAndReceiveMessage(t *testing.T) {
// TODO: Implement me
}
func TestClient_SendBundle(t *testing.T) {
// TODO: Implement me
}
func TestClient_SendMessage(t *testing.T) {
// TODO: Implement me
}
func TestClient_Close(t *testing.T) {
// TODO: Implement me
}
func TestClient_addressMatches(t *testing.T) {
cli, _ := NewClient("127.0.0.1:1234")
t.Run("match", func(t *testing.T) {
cli.addressMatches("*", "/test")
})
t.Run("notMatch", func(t *testing.T) {
cli.addressMatches("[0-9]", "/test")
})
}
func TestClient_listen(t *testing.T) {
// TODO: Implement me
}
func TestNewClient(t *testing.T) {
t.Run("correctClient", func(t *testing.T) {
cli, err := NewClient("127.0.0.1:1234")
if err != nil {
t.Errorf("expected no error but got: %v", err)
}
if cli.messageReceivers == nil {
t.Errorf("expected client message messageReceivers to be initialized.")
}
})
t.Run("wrongAddress", func(t *testing.T) {
_, err := NewClient("127.abc.0.1:1234")
if err == nil {
t.Error("expected error but none given")
}
})
}
func TestMessageReceiverFunc_ReceiveMessage(t *testing.T) {
// TODO: Implement me
}