orion/openwrt/wifi_test.go

72 lines
2.1 KiB
Go

package openwrt
import (
"fmt"
"io/ioutil"
"testing"
)
// Test GestWifiCells method with 3 Cells
func TestGetWifiCells(t *testing.T) {
cellList, err := ioutil.ReadFile("testdata/wifi_cells_output_3.txt")
if err != nil {
t.Fatal(err)
}
exec := createMockExecutor(string(cellList), "", 0)
wifi := NewWifiWithExecutor(exec, "wlan1")
_ = wifi.GetWifiCells()
if len(wifi.Cells) != 3 {
fmt.Printf("Size of wifi.Cells is %d and not 3 !!!\n", len(wifi.Cells))
t.Error("Cell list is empty ... This can not append !! Fix your code Dummy !")
}
if g, e := wifi.Cells[0].Ssid, "PyxisWifi"; g != e {
t.Errorf("The first Cell have a bad SSID !\n %s is expected and we have %s", e, g)
}
if g, e := wifi.Cells[0].MacAdress, "68:A3:78:6E:D9:24"; g != e {
t.Errorf("The first Cell have a bad MAC !\n %s is expected and we have %s", e, g)
}
if g, e := wifi.Cells[0].Encryption, "none"; g != e {
t.Errorf("The first Cell have a bad Encryption!\n %s is expected and we have %s", e, g)
}
if g, e := wifi.Cells[1].Encryption, "psk"; g != e {
t.Errorf("The second Cell have a bad Encryption!\n %s is expected and we have %s", e, g)
}
if g, e := wifi.Cells[2].MacAdress, "0C:F4:D5:16:AA:18"; g != e {
t.Errorf("The last Cell have a bad MAC !\n %s is expected and we have %s", e, g)
}
}
// Test GestWifiCells method with empty list
func TestGetWifiCellsEmpty(t *testing.T) {
exec := createMockExecutor("", "", 0)
wifi := NewWifiWithExecutor(exec, "wlan1")
_ = wifi.GetWifiCells()
if len(wifi.Cells) != 0 {
fmt.Printf("Size of wifi.Cells is %d and not 0 !!!\n", len(wifi.Cells))
t.Error("Cell list is empty ... This can not append !! Fix your code Dummy !")
}
}
// Test GestWifiCells method with 3 Cells
func TestGetWifiCellsLarge(t *testing.T) {
cellList, err := ioutil.ReadFile("testdata/wifi_cells_output_large.txt")
if err != nil {
t.Fatal(err)
}
exec := createMockExecutor(string(cellList), "", 0)
wifi := NewWifiWithExecutor(exec, "wlan1")
_ = wifi.GetWifiCells()
if len(wifi.Cells) != 49 {
fmt.Printf("Size of wifi.Cells is %d and not 49 !!!\n", len(wifi.Cells))
t.Error("Cell list is empty ... This can not append !! Fix your code Dummy !")
}
}