owrt/wifi_scanner_test.go

72 lines
2.1 KiB
Go

package owrt
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].MacAddress, "74:3e:2b:08:41:1c"; 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[1].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[2].Encryption, "psk2"; g != e {
t.Errorf("The last Cell have a bad Encryption!\n %s is expected and we have %s", e, g)
}
if g, e := wifi.Cells[2].MacAddress, "20:47:da:b7:0e:5c"; 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) != 40 {
fmt.Printf("Size of wifi.Cells is %d and not 40 !!!\n", len(wifi.Cells))
t.Error("Cell list is empty ... This can not append !! Fix your code Dummy !")
}
}