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