116 lines
2.7 KiB
Go
116 lines
2.7 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.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.GetSysDevName("testdata/sys/") != "wlan1" {
|
||
|
t.Fatalf("UCIWirelessInterface.GetDeviceSysName() failed !")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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 !")
|
||
|
}
|
||
|
}
|