-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathnet_test.go
45 lines (36 loc) · 1.03 KB
/
net_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
package net
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func must(r interface{}, err error) interface{} {
if err != nil {
panic(err)
}
return r
}
func TestLookupIP(t *testing.T) {
assert.Equal(t, "127.0.0.1", must(LookupIP("localhost")))
assert.Equal(t, "198.41.0.4", must(LookupIP("a.root-servers.net")))
}
func TestLookupIPs(t *testing.T) {
assert.Equal(t, []string{"127.0.0.1"}, must(LookupIPs("localhost")))
assert.ElementsMatch(t, []string{"1.1.1.1", "1.0.0.1"}, must(LookupIPs("one.one.one.one")))
}
func BenchmarkLookupIPs(b *testing.B) {
for i := 0; i < b.N; i++ {
must(LookupIPs("localhost"))
}
}
func TestLookupTXT(t *testing.T) {
assert.NotEmpty(t, must(LookupTXT("example.com")))
}
func TestLookupCNAME(t *testing.T) {
assert.Equal(t, "hairyhenderson.ca.", must(LookupCNAME("www.hairyhenderson.ca.")))
}
func TestLookupSRV(t *testing.T) {
srv, err := LookupSRV("_sip._udp.sip.voice.google.com")
require.NoError(t, err)
assert.Equal(t, uint16(5060), srv.Port)
}