Commit da118f7b authored by Mikio Hara's avatar Mikio Hara

route: don't fail test when at least one version of INET protocols is available

This is not perfect but is enough for during the dual IP stack era.

Fixes golang/go#19298.

Change-Id: I5f16b10fda5ddfe470edb021d9a6d7e2a642d267
Reviewed-on: https://go-review.googlesource.com/41515
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent a25ba901
...@@ -7,21 +7,28 @@ package route ...@@ -7,21 +7,28 @@ package route
import "testing" import "testing"
func TestFetchAndParseRIBOnDarwin(t *testing.T) { func TestFetchAndParseRIBOnDarwin(t *testing.T) {
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} { for _, typ := range []RIBType{sysNET_RT_FLAGS, sysNET_RT_DUMP2, sysNET_RT_IFLIST2} {
for _, typ := range []RIBType{sysNET_RT_FLAGS, sysNET_RT_DUMP2, sysNET_RT_IFLIST2} { var lastErr error
ms, err := fetchAndParseRIB(af, typ) var ms []Message
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
rs, err := fetchAndParseRIB(af, typ)
if err != nil { if err != nil {
t.Error(err) lastErr = err
continue continue
} }
ss, err := msgs(ms).validate() ms = append(ms, rs...)
if err != nil { }
t.Errorf("%v %d %v", addrFamily(af), typ, err) if len(ms) == 0 && lastErr != nil {
continue t.Error(typ, lastErr)
} continue
for _, s := range ss { }
t.Log(s) ss, err := msgs(ms).validate()
} if err != nil {
t.Error(typ, err)
continue
}
for _, s := range ss {
t.Log(s)
} }
} }
} }
...@@ -6,26 +6,32 @@ package route ...@@ -6,26 +6,32 @@ package route
import ( import (
"testing" "testing"
"time"
"unsafe" "unsafe"
) )
func TestFetchAndParseRIBOnFreeBSD(t *testing.T) { func TestFetchAndParseRIBOnFreeBSD(t *testing.T) {
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} { for _, typ := range []RIBType{sysNET_RT_IFMALIST} {
for _, typ := range []RIBType{sysNET_RT_IFMALIST} { var lastErr error
ms, err := fetchAndParseRIB(af, typ) var ms []Message
if err != nil { for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
t.Error(err) rs, err := fetchAndParseRIB(af, typ)
continue
}
ss, err := msgs(ms).validate()
if err != nil { if err != nil {
t.Errorf("%v %d %v", addrFamily(af), typ, err) lastErr = err
continue continue
} }
for _, s := range ss { ms = append(ms, rs...)
t.Log(s) }
} if len(ms) == 0 && lastErr != nil {
t.Error(typ, lastErr)
continue
}
ss, err := msgs(ms).validate()
if err != nil {
t.Error(typ, err)
continue
}
for _, s := range ss {
t.Log(s)
} }
} }
} }
...@@ -48,58 +54,38 @@ func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) { ...@@ -48,58 +54,38 @@ func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) {
{typ: sysNET_RT_IFLIST}, {typ: sysNET_RT_IFLIST},
{typ: sysNET_RT_IFLISTL}, {typ: sysNET_RT_IFLISTL},
} }
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} { for i := range tests {
var lastErr error var lastErr error
for i := 0; i < 3; i++ { for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
for j := range tests { rs, err := fetchAndParseRIB(af, tests[i].typ)
var err error if err != nil {
if tests[j].b, err = FetchRIB(af, tests[j].typ, 0); err != nil { lastErr = err
lastErr = err continue
time.Sleep(10 * time.Millisecond)
}
}
if lastErr == nil {
break
} }
tests[i].msgs = append(tests[i].msgs, rs...)
} }
if lastErr != nil { if len(tests[i].msgs) == 0 && lastErr != nil {
t.Error(af, lastErr) t.Error(tests[i].typ, lastErr)
continue continue
} }
for i := range tests { tests[i].ss, lastErr = msgs(tests[i].msgs).validate()
var err error
if tests[i].msgs, err = ParseRIB(tests[i].typ, tests[i].b); err != nil {
lastErr = err
t.Error(af, err)
}
}
if lastErr != nil { if lastErr != nil {
t.Error(tests[i].typ, lastErr)
continue continue
} }
for i := range tests { for _, s := range tests[i].ss {
var err error t.Log(s)
tests[i].ss, err = msgs(tests[i].msgs).validate()
if err != nil {
lastErr = err
t.Error(af, err)
}
for _, s := range tests[i].ss {
t.Log(s)
}
} }
if lastErr != nil { }
for i := len(tests) - 1; i > 0; i-- {
if len(tests[i].ss) != len(tests[i-1].ss) {
t.Errorf("got %v; want %v", tests[i].ss, tests[i-1].ss)
continue continue
} }
for i := len(tests) - 1; i > 0; i-- { for j, s1 := range tests[i].ss {
if len(tests[i].ss) != len(tests[i-1].ss) { s0 := tests[i-1].ss[j]
t.Errorf("got %v; want %v", tests[i].ss, tests[i-1].ss) if s1 != s0 {
continue t.Errorf("got %s; want %s", s1, s0)
}
for j, s1 := range tests[i].ss {
s0 := tests[i-1].ss[j]
if s1 != s0 {
t.Errorf("got %s; want %s", s1, s0)
}
} }
} }
} }
......
...@@ -14,21 +14,28 @@ import ( ...@@ -14,21 +14,28 @@ import (
) )
func TestFetchAndParseRIB(t *testing.T) { func TestFetchAndParseRIB(t *testing.T) {
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} { for _, typ := range []RIBType{sysNET_RT_DUMP, sysNET_RT_IFLIST} {
for _, typ := range []RIBType{sysNET_RT_DUMP, sysNET_RT_IFLIST} { var lastErr error
ms, err := fetchAndParseRIB(af, typ) var ms []Message
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
rs, err := fetchAndParseRIB(af, typ)
if err != nil { if err != nil {
t.Error(err) lastErr = err
continue
}
ss, err := msgs(ms).validate()
if err != nil {
t.Errorf("%v %d %v", addrFamily(af), typ, err)
continue continue
} }
for _, s := range ss { ms = append(ms, rs...)
t.Log(s) }
} if len(ms) == 0 && lastErr != nil {
t.Error(typ, lastErr)
continue
}
ss, err := msgs(ms).validate()
if err != nil {
t.Error(typ, err)
continue
}
for _, s := range ss {
t.Log(typ, s)
} }
} }
} }
...@@ -145,8 +152,8 @@ func TestRouteMessage(t *testing.T) { ...@@ -145,8 +152,8 @@ func TestRouteMessage(t *testing.T) {
var ms []RouteMessage var ms []RouteMessage
for _, af := range []int{sysAF_INET, sysAF_INET6} { for _, af := range []int{sysAF_INET, sysAF_INET6} {
rs, err := fetchAndParseRIB(af, sysNET_RT_DUMP) if _, err := fetchAndParseRIB(af, sysNET_RT_DUMP); err != nil {
if err != nil || len(rs) == 0 { t.Log(err)
continue continue
} }
switch af { switch af {
...@@ -228,6 +235,5 @@ func TestRouteMessage(t *testing.T) { ...@@ -228,6 +235,5 @@ func TestRouteMessage(t *testing.T) {
for _, s := range ss { for _, s := range ss {
t.Log(s) t.Log(s)
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment