forked from blessnetwork/b7s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost_internal_test.go
88 lines (82 loc) · 1.81 KB
/
host_internal_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
86
87
88
package host
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestDetermineAddressProtocol(t *testing.T) {
tests := []struct {
address string
shouldErr bool
protocol string
}{
{
address: "127.0.0.1",
shouldErr: false,
protocol: "ip4",
},
{
address: "192.168.0.1",
shouldErr: false,
protocol: "ip4",
},
{
address: "::FFFF:C0A8:1",
shouldErr: false,
protocol: "ip6",
},
{
address: "0000:0000:0000:0000:0000:FFFF:C0A8:1",
shouldErr: false,
protocol: "ip6",
},
{
address: "example.com",
shouldErr: false,
protocol: "dns",
},
{
address: "foo1.bar2.com.gah.zip",
shouldErr: false,
protocol: "dns",
},
{
address: "foo1.bar2.com.gah.zip",
shouldErr: false,
protocol: "dns",
},
{
address: "hostname",
shouldErr: false,
protocol: "dns",
},
{
address: "",
shouldErr: true,
},
{
address: "698.168.0.1",
shouldErr: true,
},
{
// Documenting that we do NOT support support certain things:
//
// While the Domain Name System (DNS) technically supports arbitrary sequences of octets in domain name labels,
// the DNS standards recommend the use of the LDH (letter-digit-hyphen) subset of ASCII conventionally used for
// host names, and require that string comparisons between DNS domain names should be case-insensitive.
//
// See => https://en.wikipedia.org/wiki/Punycode
address: "例子.測試",
shouldErr: true,
},
}
for _, test := range tests {
protocol, address, err := determineAddressProtocol(test.address)
if test.shouldErr {
require.Error(t, err)
break
}
require.NoError(t, err)
require.Equal(t, test.address, address)
require.Equalf(t, test.protocol, protocol, "unexpected protocol for address: %s", test.address)
}
}