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
|
package server
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseHost(t *testing.T) {
tsts := []struct {
name string
host string
expectNetwork string
expectAddr string
}{
{
name: "schemeless tcp host defaults to tcp",
host: "127.0.0.1:50051",
expectNetwork: "tcp",
expectAddr: "127.0.0.1:50051",
},
{
name: "schemeless with only port defaults to tcp",
host: ":50051",
expectNetwork: "tcp",
expectAddr: ":50051",
},
{
name: "unix socket",
host: "unix:///var/run/gobgp.socket",
expectNetwork: "unix",
expectAddr: "/var/run/gobgp.socket",
},
}
for _, tst := range tsts {
t.Run(tst.name, func(t *testing.T) {
gotNetwork, gotAddr := parseHost(tst.host)
assert.Equal(t, tst.expectNetwork, gotNetwork)
assert.Equal(t, tst.expectAddr, gotAddr)
})
}
}
|