-
Notifications
You must be signed in to change notification settings - Fork 1
/
codec_client_test.go
51 lines (48 loc) · 1.1 KB
/
codec_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
// Copyright (c) 2019 Meng Huang ([email protected])
// This package is licensed under a MIT license that can be found in the LICENSE file.
package rpc
import (
"github.com/hslam/socket"
"sync"
"testing"
)
func TestNewClientCodec(t *testing.T) {
network := "tcp"
addr := ":9999"
wg := sync.WaitGroup{}
wg.Add(1)
sock, _ := socket.NewSocket(network, nil)
lis, _ := sock.Listen(addr)
go func() {
defer wg.Done()
for {
_, err := lis.Accept()
if err != nil {
break
}
}
}()
conn, _ := sock.Dial(addr)
message := conn.Messages()
headerEncoder := NewHeaderEncoder("json")
if NewClientCodec(nil, nil, nil, bufferSize) != nil {
t.Error("should be nil")
}
if NewClientCodec(nil, nil, message, bufferSize) != nil {
t.Error("should be nil")
}
codec := NewClientCodec(nil, headerEncoder(), message, bufferSize)
if codec == nil {
t.Error("should not be nil")
}
if codec.ReadResponseBody(nil, nil) == nil {
t.Error("The err should not be nil")
}
message.Close()
codec.Close()
if codec.ReadResponseHeader(nil) == nil {
t.Error("The err should not be nil")
}
lis.Close()
wg.Wait()
}