-
Notifications
You must be signed in to change notification settings - Fork 411
/
helper_test.go
78 lines (69 loc) · 2 KB
/
helper_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
package erpc_test
import (
"testing"
"github.com/andeya/erpc/v7"
"github.com/stretchr/testify/assert"
)
func TestHTTPServiceMethodMapper(t *testing.T) {
var cases = []struct{ src, dst string }{
{"AaBb", "/aa_bb"},
{"ABcXYz", "/abc_xyz"},
{"Aa__Bb", "/aa_bb"},
{"Aa________Bb", "/aa_bb"},
{"aa__bb", "/aa_bb"},
{"ABC__XYZ", "/abc_xyz"},
{"Aa_Bb", "/aa/bb"},
{"aa_bb", "/aa/bb"},
{"ABC_XYZ", "/abc/xyz"},
}
for _, c := range cases {
got := erpc.HTTPServiceMethodMapper("", c.src)
if got != c.dst {
t.Fatalf("%s: got: %s, expect: %s", c.src, got, c.dst)
}
}
}
func TestRPCServiceMethodMapper(t *testing.T) {
var cases = []struct{ src, dst string }{
{"AaBb", "AaBb"},
{"ABcXYz", "ABcXYz"},
{"Aa__Bb", "Aa_Bb"},
{"Aa________Bb", "Aa_Bb"},
{"aa__bb", "aa_bb"},
{"ABC__XYZ", "ABC_XYZ"},
{"Aa_Bb", "Aa.Bb"},
{"aa_bb", "aa.bb"},
{"ABC_XYZ", "ABC.XYZ"},
}
for _, c := range cases {
got := erpc.RPCServiceMethodMapper("", c.src)
if got != c.dst {
t.Fatalf("%s: got: %s, expect: %s", c.src, got, c.dst)
}
}
}
func TestFakeAddr(t *testing.T) {
addr := erpc.NewFakeAddr("", "", "")
assert.Equal(t, "0.0.0.0:0", addr.String())
assert.Equal(t, "tcp", addr.Network())
addr = erpc.NewFakeAddr("tcp", "", "1234")
assert.Equal(t, "0.0.0.0:1234", addr.String())
addr, err := erpc.NewFakeAddr2("", "")
assert.NoError(t, err)
assert.Equal(t, "0.0.0.0:0", addr.String())
assert.Equal(t, "tcp", addr.Network())
assert.Equal(t, "0.0.0.0", addr.Host())
assert.Equal(t, "0", addr.Port())
addr, err = erpc.NewFakeAddr2("tcp6", ":1234")
assert.NoError(t, err)
assert.Equal(t, "0.0.0.0:1234", addr.String())
assert.Equal(t, "tcp6", addr.Network())
assert.Equal(t, "0.0.0.0", addr.Host())
assert.Equal(t, "1234", addr.Port())
addr, err = erpc.NewFakeAddr2("tcp6", "192.0.0.10:1234")
assert.NoError(t, err)
assert.Equal(t, "192.0.0.10:1234", addr.String())
assert.Equal(t, "tcp6", addr.Network())
assert.Equal(t, "192.0.0.10", addr.Host())
assert.Equal(t, "1234", addr.Port())
}