-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialer_test.go
85 lines (80 loc) · 1.89 KB
/
dialer_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
// 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/rpc/examples/codec/json/service"
"sync"
"testing"
"time"
)
func TestDial(t *testing.T) {
addr := ":8880"
network := ""
codec := ""
if _, err := Dial(network, addr, codec); err == nil {
t.Error("The err should not be nil")
}
network = "tcp"
if _, err := Dial(network, addr, codec); err == nil {
t.Error("The err should not be nil")
}
}
func TestDialTLS(t *testing.T) {
addr := ":8880"
network := ""
codec := ""
if _, err := DialTLS(network, addr, codec, SkipVerifyTLSConfig()); err == nil {
t.Error("The err should not be nil")
}
network = "tcp"
if _, err := DialTLS(network, addr, codec, SkipVerifyTLSConfig()); err == nil {
t.Error("The err should not be nil")
}
}
func TestDialWithOptions(t *testing.T) {
addr := ":9999"
opts := &Options{}
opts.Network = "tcp"
opts.Codec = "json"
err := Register(new(service.Arith))
if err != nil {
t.Error(err)
}
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
ListenWithOptions(addr, opts)
}()
time.Sleep(time.Millisecond * 10)
opts.Network = ""
opts.Codec = ""
if _, err := DialWithOptions(addr, opts); err == nil {
t.Error("The err should not be nil")
}
opts.Codec = "json"
if _, err := DialWithOptions(addr, opts); err == nil {
t.Error("The err should not be nil")
}
opts.Codec = ""
opts.NewCodec = NewCodec("json")
opts.NewSocket = NewSocket("tcp")
if conn, err := DialWithOptions(addr, opts); err != nil {
t.Error(err)
} else {
conn.Close()
}
if conn, err := DialWithOptions(addr, opts); err != nil {
t.Error(err)
} else {
conn.Close()
}
opts.NewHeaderEncoder = NewHeaderEncoder("json")
if conn, err := DialWithOptions(addr, opts); err != nil {
t.Error(err)
} else {
conn.Close()
}
DefaultServer.Close()
wg.Wait()
}