github.com/icodeface/tls@v0.0.0-20230910023335-34df9250cd12/internal/x/net/lif/link_test.go (about) 1 // Copyright 2016 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 // +build solaris 6 7 package lif 8 9 import ( 10 "fmt" 11 "testing" 12 ) 13 14 func (ll *Link) String() string { 15 return fmt.Sprintf("name=%s index=%d type=%d flags=%#x mtu=%d addr=%v", ll.Name, ll.Index, ll.Type, ll.Flags, ll.MTU, llAddr(ll.Addr)) 16 } 17 18 type linkPack struct { 19 af int 20 lls []Link 21 } 22 23 func linkPacks() ([]linkPack, error) { 24 var lastErr error 25 var lps []linkPack 26 for _, af := range [...]int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} { 27 lls, err := Links(af, "") 28 if err != nil { 29 lastErr = err 30 continue 31 } 32 lps = append(lps, linkPack{af: af, lls: lls}) 33 } 34 return lps, lastErr 35 } 36 37 func TestLinks(t *testing.T) { 38 lps, err := linkPacks() 39 if len(lps) == 0 && err != nil { 40 t.Fatal(err) 41 } 42 for _, lp := range lps { 43 n := 0 44 for _, sll := range lp.lls { 45 lls, err := Links(lp.af, sll.Name) 46 if err != nil { 47 t.Fatal(lp.af, sll.Name, err) 48 } 49 for _, ll := range lls { 50 if ll.Name != sll.Name || ll.Index != sll.Index { 51 t.Errorf("af=%s got %v; want %v", addrFamily(lp.af), &ll, &sll) 52 continue 53 } 54 t.Logf("af=%s name=%s %v", addrFamily(lp.af), sll.Name, &ll) 55 n++ 56 } 57 } 58 if n != len(lp.lls) { 59 t.Errorf("af=%s got %d; want %d", addrFamily(lp.af), n, len(lp.lls)) 60 continue 61 } 62 } 63 }