Debian Codegraph @

cmd/atomdns/internal/localaddr/localaddr_test.go

raw
1 package localaddr
2
3 import (
4 "net"
5 "testing"
6
7 "codeberg.org/miekg/dns/dnsutil"
8 )
9
10 func TestSource(t *testing.T) {
11 testcases := []struct {
12 sources []string
13 fam int
14 exp net.IP
15 }{
16 {[]string{"127.0.0.1"}, dnsutil.IPv6Family, nil},
17 {[]string{"127.0.0.1"}, dnsutil.IPv4Family, net.ParseIP("127.0.0.1").To4()},
18 {[]string{"127.0.0.1", "::1"}, dnsutil.IPv4Family, net.ParseIP("127.0.0.1").To4()},
19 {[]string{"127.0.0.1", "::1"}, dnsutil.IPv6Family, net.ParseIP("::1")},
20 {[]string{"127.0.0.1:53", "[::1]:53"}, dnsutil.IPv6Family, net.ParseIP("::1")},
21 {[]string{"::1"}, dnsutil.IPv4Family, nil},
22 {[]string{}, dnsutil.IPv4Family, nil},
23 }
24 for i, tc := range testcases {
25 got := Source(tc.fam, tc.sources)
26 if !tc.exp.Equal(got) {
27 t.Errorf("test %d, expected %q, got %q", i, tc.exp, got)
28
29 }
30 }
31 }