message_freebsd_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. package route
  5. import "testing"
  6. func TestFetchAndParseRIBOnFreeBSD(t *testing.T) {
  7. for _, typ := range []RIBType{sysNET_RT_IFMALIST} {
  8. var lastErr error
  9. var ms []Message
  10. for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
  11. rs, err := fetchAndParseRIB(af, typ)
  12. if err != nil {
  13. lastErr = err
  14. continue
  15. }
  16. ms = append(ms, rs...)
  17. }
  18. if len(ms) == 0 && lastErr != nil {
  19. t.Error(typ, lastErr)
  20. continue
  21. }
  22. ss, err := msgs(ms).validate()
  23. if err != nil {
  24. t.Error(typ, err)
  25. continue
  26. }
  27. for _, s := range ss {
  28. t.Log(s)
  29. }
  30. }
  31. }
  32. func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) {
  33. if _, err := FetchRIB(sysAF_UNSPEC, sysNET_RT_IFLISTL, 0); err != nil {
  34. t.Skip("NET_RT_IFLISTL not supported")
  35. }
  36. if compatFreeBSD32 {
  37. t.Skip("NET_RT_IFLIST vs. NET_RT_IFLISTL doesn't work for 386 emulation on amd64")
  38. }
  39. var tests = [2]struct {
  40. typ RIBType
  41. b []byte
  42. msgs []Message
  43. ss []string
  44. }{
  45. {typ: sysNET_RT_IFLIST},
  46. {typ: sysNET_RT_IFLISTL},
  47. }
  48. for i := range tests {
  49. var lastErr error
  50. for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
  51. rs, err := fetchAndParseRIB(af, tests[i].typ)
  52. if err != nil {
  53. lastErr = err
  54. continue
  55. }
  56. tests[i].msgs = append(tests[i].msgs, rs...)
  57. }
  58. if len(tests[i].msgs) == 0 && lastErr != nil {
  59. t.Error(tests[i].typ, lastErr)
  60. continue
  61. }
  62. tests[i].ss, lastErr = msgs(tests[i].msgs).validate()
  63. if lastErr != nil {
  64. t.Error(tests[i].typ, lastErr)
  65. continue
  66. }
  67. for _, s := range tests[i].ss {
  68. t.Log(s)
  69. }
  70. }
  71. for i := len(tests) - 1; i > 0; i-- {
  72. if len(tests[i].ss) != len(tests[i-1].ss) {
  73. t.Errorf("got %v; want %v", tests[i].ss, tests[i-1].ss)
  74. continue
  75. }
  76. for j, s1 := range tests[i].ss {
  77. s0 := tests[i-1].ss[j]
  78. if s1 != s0 {
  79. t.Errorf("got %s; want %s", s1, s0)
  80. }
  81. }
  82. }
  83. }