k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/third_party/forked/golang/net/dnsclient_test.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // This package is copied from Go library net. 6 // https://golang.org/src/net/dnsclient.go 7 // The original private function reverseaddr 8 // is exported as public function. 9 10 package net 11 12 import ( 13 "net" 14 "testing" 15 ) 16 17 func TestReverseaddr(t *testing.T) { 18 var revAddrTests = []struct { 19 Addr string 20 Reverse string 21 ErrPrefix string 22 }{ 23 {"1.2.3.4", "4.3.2.1.in-addr.arpa.", ""}, 24 {"245.110.36.114", "114.36.110.245.in-addr.arpa.", ""}, 25 {"::ffff:12.34.56.78", "78.56.34.12.in-addr.arpa.", ""}, 26 {"::1", "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.", ""}, 27 {"1::", "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.ip6.arpa.", ""}, 28 {"1234:567::89a:bcde", "e.d.c.b.a.9.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.7.6.5.0.4.3.2.1.ip6.arpa.", ""}, 29 {"1234:567:fefe:bcbc:adad:9e4a:89a:bcde", "e.d.c.b.a.9.8.0.a.4.e.9.d.a.d.a.c.b.c.b.e.f.e.f.7.6.5.0.4.3.2.1.ip6.arpa.", ""}, 30 {"1.2.3", "", "unrecognized address"}, 31 {"1.2.3.4.5", "", "unrecognized address"}, 32 {"1234:567:bcbca::89a:bcde", "", "unrecognized address"}, 33 {"1234:567::bcbc:adad::89a:bcde", "", "unrecognized address"}, 34 } 35 for i, tt := range revAddrTests { 36 a, err := Reverseaddr(tt.Addr) 37 if len(tt.ErrPrefix) > 0 && err == nil { 38 t.Errorf("#%d: expected %q, got <nil> (error)", i, tt.ErrPrefix) 39 continue 40 } 41 if len(tt.ErrPrefix) == 0 && err != nil { 42 t.Errorf("#%d: expected <nil>, got %q (error)", i, err) 43 } 44 if err != nil && err.(*net.DNSError).Err != tt.ErrPrefix { 45 t.Errorf("#%d: expected %q, got %q (mismatched error)", i, tt.ErrPrefix, err.(*net.DNSError).Err) 46 } 47 if a != tt.Reverse { 48 t.Errorf("#%d: expected %q, got %q (reverse address)", i, tt.Reverse, a) 49 } 50 } 51 }