From b34ccd3dee589e4720b2b9a537b8b75195e31702 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Fri, 21 Sep 2018 14:36:06 +0200 Subject: [PATCH] Improving network_test.go ... This way we don't need a real wifi card --- openwrt/network.go | 8 ++++++-- openwrt/network_test.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/openwrt/network.go b/openwrt/network.go index 2384829..6ba5d47 100644 --- a/openwrt/network.go +++ b/openwrt/network.go @@ -37,11 +37,15 @@ func (n *Network) ListInterfaces() []net.Interface { } // ListWirelessInterfaces list all wifi cards -func (n *Network) ListWirelessInterfaces() []net.Interface { +// you need to provide the wireless file or "" to use +// Linux default one "/proc/net/wireless" +func (n *Network) ListWirelessInterfaces(wifiFile string) []net.Interface { var result []net.Interface var ifaceNames []string - wifiFile := "/proc/net/wireless" + if wifiFile == "" { + wifiFile = "/proc/net/wireless" + } wifiFileContent, err := ioutil.ReadFile(wifiFile) check(err) diff --git a/openwrt/network_test.go b/openwrt/network_test.go index 89b6f1a..bac8574 100644 --- a/openwrt/network_test.go +++ b/openwrt/network_test.go @@ -15,7 +15,7 @@ func TestNetworkListInterfaces(t *testing.T) { func TestListWirelessInterfaces(t *testing.T) { net := NewNetwork() - res := net.ListWirelessInterfaces() + res := net.ListWirelessInterfaces("./testdata/proc_net_wireless.txt") for _, el := range res { fmt.Printf("%s\n", el.Name) }