summaryrefslogtreecommitdiff
path: root/net/net_test.go
blob: 33223100a6bf9072b8f149adfbc6f1eec4266d54 (plain)
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
package net

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

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, "35.196.83.195", must(LookupIP("hairyhenderson.ca")))
	assert.Equal(t, "93.184.216.34", must(LookupIP("example.com")))
}

func TestLookupIPs(t *testing.T) {
	assert.Equal(t, []string{"127.0.0.1"}, must(LookupIPs("localhost")))
	assert.Equal(t, []string{"35.196.83.195"}, must(LookupIPs("hairyhenderson.ca")))
	assert.Equal(t, []string{"93.184.216.34"}, must(LookupIPs("example.com")))
}

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")
	assert.NoError(t, err)
	assert.Equal(t, uint16(5060), srv.Port)
}