-
Notifications
You must be signed in to change notification settings - Fork 56
/
utils_test.go
70 lines (67 loc) · 1.45 KB
/
utils_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
// Copyright 2018 The go-zeromq Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zmq4
import (
"fmt"
"testing"
)
func TestSplitAddr(t *testing.T) {
testCases := []struct {
desc string
v string
network string
addr string
err error
}{
{
desc: "tcp wild",
v: "tcp://*:5000",
network: "tcp",
addr: "0.0.0.0:5000",
err: nil,
},
{
desc: "tcp ipv4",
v: "tcp://127.0.0.1:6000",
network: "tcp",
addr: "127.0.0.1:6000",
err: nil,
},
{
desc: "tcp ipv6",
v: "tcp://[::1]:7000",
network: "tcp",
addr: "[::1]:7000",
err: nil,
},
{
desc: "ipc",
v: "ipc://some-ep",
network: "ipc",
addr: "some-ep",
err: nil,
},
{
desc: "inproc",
v: "inproc://some-ep",
network: "inproc",
addr: "some-ep",
err: nil,
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
network, addr, err := splitAddr(tc.v)
if network != tc.network {
t.Fatalf("unexpected network: got=%v, want=%v", network, tc.network)
}
if addr != tc.addr {
t.Fatalf("unexpected address: got=%q, want=%q", addr, tc.addr)
}
if fmt.Sprintf("%+v", err) != fmt.Sprintf("%+v", tc.err) { // nil-safe comparison errors by value
t.Fatalf("unexpected error: got=%+v, want=%+v", err, tc.err)
}
})
}
}