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.

63 lines
1.4 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 lastErr error
  19. var lps []linkPack
  20. for _, af := range [...]int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
  21. lls, err := Links(af, "")
  22. if err != nil {
  23. lastErr = err
  24. continue
  25. }
  26. lps = append(lps, linkPack{af: af, lls: lls})
  27. }
  28. return lps, lastErr
  29. }
  30. func TestLinks(t *testing.T) {
  31. lps, err := linkPacks()
  32. if len(lps) == 0 && err != nil {
  33. t.Fatal(err)
  34. }
  35. for _, lp := range lps {
  36. n := 0
  37. for _, sll := range lp.lls {
  38. lls, err := Links(lp.af, sll.Name)
  39. if err != nil {
  40. t.Fatal(lp.af, sll.Name, err)
  41. }
  42. for _, ll := range lls {
  43. if ll.Name != sll.Name || ll.Index != sll.Index {
  44. t.Errorf("af=%s got %v; want %v", addrFamily(lp.af), &ll, &sll)
  45. continue
  46. }
  47. t.Logf("af=%s name=%s %v", addrFamily(lp.af), sll.Name, &ll)
  48. n++
  49. }
  50. }
  51. if n != len(lp.lls) {
  52. t.Errorf("af=%s got %d; want %d", addrFamily(lp.af), n, len(lp.lls))
  53. continue
  54. }
  55. }
  56. }