test nits

parent a7cc795b
Go Netroute
===
[![Build Status](https://travis-ci.com/willscott/go-netroute.svg?branch=master)](https://travis-ci.com/willscott/go-netroute)
A cross-platform implementation of the [`gopacket/routing.Router`](https://godoc.org/github.com/google/gopacket/routing#Router) interface.
This library uses `gopacket` for linux, `x/net/route`
......
......@@ -168,7 +168,7 @@ func toIPAddr(a route.Addr) (net.IP, error) {
copy(ip, t.IP[:])
return ip, nil
default:
return net.IP{}, fmt.Errorf("unknown family: %T", t)
return net.IP{}, fmt.Errorf("unknown family: %v", t)
}
}
......
......@@ -2,6 +2,7 @@ package netroute
import (
"net"
"strings"
"testing"
)
......@@ -11,12 +12,25 @@ func TestRoute(t *testing.T) {
t.Fatal(err)
}
// Route to 127.0.0.1 shouldn't have a gateway
_, gw, _, err := r.Route(net.IPv4(127, 0, 0, 1))
ifs, err := net.Interfaces()
if err != nil || len(ifs) == 0 {
t.Skip("Can't test routing without access to system interfaces")
}
var localAddr net.IP
addrs, err := ifs[0].Addrs()
for _, addr := range addrs {
if strings.HasPrefix(addr.Network(), "ip") {
localAddr, _, _ = net.ParseCIDR(addr.String())
break
}
}
_, gw, src, err := r.Route(localAddr)
if err != nil {
t.Fatal(err)
}
if gw != nil {
if gw != nil || !src.Equal(localAddr) {
t.Fatalf("Did not expect gateway to localhost: %v", gw)
}
......
......@@ -174,7 +174,7 @@ func getIface(index uint32) *net.Interface {
ifRow.Index = index
err := windows.GetIfEntry(&ifRow)
if err != nil {
return il
return nil
}
ifaces, err := net.Interfaces()
......@@ -182,7 +182,7 @@ func getIface(index uint32) *net.Interface {
return nil
}
for _, iface := range ifaces {
if bytes.Equal(iface.HardwareAddr, ifRow.PhysAddr) {
if bytes.Equal(iface.HardwareAddr, ifRow.PhysAddr[:]) {
return &iface
}
}
......@@ -200,10 +200,10 @@ func (r *winRouter) RouteWithSrc(input net.HardwareAddr, src, dst net.IP) (iface
if err != nil {
return nil, nil, nil, err
}
iface := getIface(route.index)
iface = getIface(route.index)
if route.nextHop.Addr.Family == 0 /* AF_UNDEF */ {
return nil, nil, pref, nil
return iface, nil, pref, nil
}
addr, err := route.nextHop.Sockaddr()
if err != nil {
......@@ -211,7 +211,7 @@ func (r *winRouter) RouteWithSrc(input net.HardwareAddr, src, dst net.IP) (iface
}
nextHop, _ := sockaddrnet.SockaddrToIPAndZone(addr)
return nil, nextHop, pref, nil
return iface, nextHop, pref, nil
}
func New() (routing.Router, error) {
......
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