This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/openwrt/uci_wireless_interface_test.go

120 lines
2.9 KiB
Go

package openwrt
import (
"testing"
)
func TestGetSysDevName(t *testing.T) {
iface := NewUCIWirelessInterface()
iface.Name = "Test"
iface.Index = 1
iface.Device = "radioX"
iface.DevicePath = "soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0"
iface.Mode = "ap"
iface.Ssid = "PyxisWifi"
iface.Bssid = "00:00:00:00:00"
iface.Network = "Pyxis"
iface.Encryption = "psk"
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
if g, e := iface.GetSysDevName("testdata/sys/"), "wlan1"; g != e {
t.Fatalf("UCIWirelessInterface.GetDeviceSysName() failed ! Got: %s Expect: %s", g, e)
}
iface.SysDevName = "wlanX"
if g, e := iface.GetSysDevName("testdata/sys/"), "wlanX"; g != e {
t.Fatalf("UCIWirelessInterface.GetDeviceSysName() failed ! Got: %s Expect: %s", g, e)
}
}
func TestCreate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec)
iface := NewUCIWirelessInterface()
iface.Name = "Test"
iface.Device = "radioX"
iface.Mode = "ap"
iface.Ssid = "PyxisWifi"
iface.Bssid = "00:00:00:00:00"
iface.Network = "Pyxis"
iface.Encryption = "psk"
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
if iface.Create(uci).ReturnCode != 0 {
t.Fatalf("UCIWirelessInterface.Create() failed !")
}
}
func TestUpdate(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec)
iface := NewUCIWirelessInterface()
iface.Name = "Test"
iface.Index = 1
iface.Device = "radioX"
iface.SysDevName = "wlanX"
iface.Mode = "ap"
iface.Ssid = "PyxisWifi"
iface.Bssid = "00:00:00:00:00"
iface.Network = "Pyxis"
iface.Encryption = "psk"
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
if iface.Create(uci).ReturnCode != 0 {
t.Fatalf("UCIWirelessInterface.Create() failed !")
}
iface.Name = "Tutu"
if iface.Update(uci).ReturnCode != 0 {
t.Fatalf("UCIWirelessInterface.Update() failed !")
}
}
func TestDelete(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec)
iface := NewUCIWirelessInterface()
iface.Name = "Test"
iface.Index = 1
iface.Device = "radioX"
iface.SysDevName = "wlanX"
iface.Mode = "ap"
iface.Ssid = "PyxisWifi"
iface.Bssid = "00:00:00:00:00"
iface.Network = "Pyxis"
iface.Encryption = "psk"
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
if iface.Delete(uci).ReturnCode != 0 {
t.Fatalf("UCIWirelessInterface.Delete() failed !")
}
}
func TestConnect(t *testing.T) {
exec := createMockExecutor("", "", 0)
uci := NewUCIWithExecutor(exec)
iface := NewUCIWirelessInterface()
iface.Name = "Test"
iface.Index = 1
iface.Device = "radioX"
iface.SysDevName = "wlanX"
iface.Mode = "ap"
iface.Ssid = "PyxisWifi"
iface.Bssid = "00:00:00:00:00"
iface.Network = "Pyxis"
iface.Encryption = "psk"
iface.Key = "qsmdflkjqslmdfkjqslmfkdj"
wifiCell := NewWifiCell("PyxisWifi", "01:01:01:01:01", "psk")
if iface.Connect(uci, wifiCell, "Toto").ReturnCode != 0 {
t.Fatalf("UCIWirelessInterface.Delete() failed !")
}
}