github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/net/net_test.go (about) 1 package net 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func must(r interface{}, err error) interface{} { 11 if err != nil { 12 panic(err) 13 } 14 return r 15 } 16 17 func TestLookupIP(t *testing.T) { 18 assert.Equal(t, "127.0.0.1", must(LookupIP("localhost"))) 19 assert.Equal(t, "198.41.0.4", must(LookupIP("a.root-servers.net"))) 20 } 21 22 func TestLookupIPs(t *testing.T) { 23 assert.Equal(t, []string{"127.0.0.1"}, must(LookupIPs("localhost"))) 24 assert.ElementsMatch(t, []string{"1.1.1.1", "1.0.0.1"}, must(LookupIPs("one.one.one.one"))) 25 } 26 27 func BenchmarkLookupIPs(b *testing.B) { 28 for i := 0; i < b.N; i++ { 29 must(LookupIPs("localhost")) 30 } 31 } 32 33 func TestLookupTXT(t *testing.T) { 34 assert.NotEmpty(t, must(LookupTXT("example.com"))) 35 } 36 37 func TestLookupCNAME(t *testing.T) { 38 assert.Equal(t, "hairyhenderson.ca.", must(LookupCNAME("www.hairyhenderson.ca."))) 39 } 40 41 func TestLookupSRV(t *testing.T) { 42 srv, err := LookupSRV("_sip._udp.sip.voice.google.com") 43 require.NoError(t, err) 44 assert.Equal(t, uint16(5060), srv.Port) 45 }