You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
1.3 KiB

  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. // +build solaris
  5. package lif
  6. import (
  7. "fmt"
  8. "testing"
  9. )
  10. func (ll *Link) String() string {
  11. 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))
  12. }
  13. type linkPack struct {
  14. af int
  15. lls []Link
  16. }
  17. func linkPacks() ([]linkPack, error) {
  18. var lps []linkPack
  19. for _, af := range [...]int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
  20. lls, err := Links(af, "")
  21. if err != nil {
  22. return nil, err
  23. }
  24. lps = append(lps, linkPack{af: af, lls: lls})
  25. }
  26. return lps, nil
  27. }
  28. func TestLinks(t *testing.T) {
  29. lps, err := linkPacks()
  30. if len(lps) == 0 && err != nil {
  31. t.Fatal(err)
  32. }
  33. for _, lp := range lps {
  34. n := 0
  35. for _, sll := range lp.lls {
  36. lls, err := Links(lp.af, sll.Name)
  37. if err != nil {
  38. t.Fatal(lp.af, sll.Name, err)
  39. }
  40. for _, ll := range lls {
  41. if ll.Name != sll.Name || ll.Index != sll.Index {
  42. t.Errorf("af=%s got %v; want %v", addrFamily(lp.af), &ll, &sll)
  43. continue
  44. }
  45. t.Logf("af=%s name=%s %v", addrFamily(lp.af), sll.Name, &ll)
  46. n++
  47. }
  48. }
  49. if n != len(lp.lls) {
  50. t.Errorf("af=%s got %d; want %d", addrFamily(lp.af), n, len(lp.lls))
  51. continue
  52. }
  53. }
  54. }