From 7bff3bba79d1bd728fbafd8db8fffa855513e109 Mon Sep 17 00:00:00 2001 From: Kent Gruber Date: Tue, 1 May 2018 12:41:21 -0400 Subject: [PATCH] add test for FindInterface in network package --- network/net_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/network/net_test.go b/network/net_test.go index b20b4588..636aed84 100644 --- a/network/net_test.go +++ b/network/net_test.go @@ -118,3 +118,29 @@ func TestMatchByAddress(t *testing.T) { t.Error("unable to verify a match with a given interface and ip address") } } + +func TestFindInterface(t *testing.T) { + ifaces, err := net.Interfaces() + if err != nil { + t.Error(err) + } + if len(ifaces) <= 0 { + t.Error("Unable to find any network interfaces to run test with.") + } + var exampleIface net.Interface + // emulate libpcap's pcap_lookupdev function to find + // default interface to test with ( maybe could use loopback ? ) + for _, iface := range ifaces { + if iface.HardwareAddr != nil { + exampleIface = iface + break + } + } + foundEndpoint, err := FindInterface(exampleIface.Name) + if err != nil { + t.Error("unable to find a given interface by name to build endpoint", err) + } + if foundEndpoint.Name() != exampleIface.Name { + t.Error("unable to find a given interface by name to build endpoint") + } +}