-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
49 lines (39 loc) · 906 Bytes
/
client_test.go
File metadata and controls
49 lines (39 loc) · 906 Bytes
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
package district_test
import (
"context"
"testing"
district "github.com/KVRes/District"
"github.com/KVRes/District/rpc"
"github.com/KVRes/District/serv"
)
const addr = "localhost:8190"
func TestClient(t *testing.T) {
server := serv.NewServer()
go server.Run("tcp", addr)
client, err := district.NewClient(addr)
if err != nil {
t.Fatal(err)
}
client.RegisterChannel(context.Background(), &rpc.RegisterChannelRequest{
Namespace: "test",
Buf: 1024,
})
client.SendMessage(context.Background(), &rpc.SendMessageRequest{
Namespace: "test",
Msg: "hello",
})
t.Log(client.Info(context.Background(), &rpc.InfoRequest{
Namespace: "test",
}))
stream, err := client.ReceiveMessage(context.Background(), &rpc.ReceiveMessageRequest{
Namespace: "test",
})
if err != nil {
t.Fatal(err)
}
msg, err := stream.Recv()
if err != nil {
t.Fatal(err)
}
t.Log(msg)
}