2018-09-24 17:38:17 +02:00
|
|
|
package openwrt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2018-10-08 15:39:16 +02:00
|
|
|
const (
|
|
|
|
ifaceName = "Test"
|
|
|
|
ifaceNetwork = "Pyxis"
|
|
|
|
ifaceSysDevName = "wlanX"
|
|
|
|
ifaceEnc = "psk"
|
|
|
|
ifaceSSID = "PyxisWifi"
|
|
|
|
ifaceKey = "qsmdflkjqslmdfkjqslmfkdj"
|
|
|
|
ifaceDevice = "radioX"
|
|
|
|
ifaceMode = "ap"
|
|
|
|
ifaceBssid = "00:00:00:00:00"
|
|
|
|
)
|
|
|
|
|
2018-09-24 17:38:17 +02:00
|
|
|
func TestGetSysDevName(t *testing.T) {
|
|
|
|
iface := NewUCIWirelessInterface()
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Name = ifaceName
|
2018-09-24 17:38:17 +02:00
|
|
|
iface.Index = 1
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Device = ifaceDevice
|
2018-09-24 17:38:17 +02:00
|
|
|
iface.DevicePath = "soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0"
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Mode = ifaceMode
|
|
|
|
iface.Ssid = ifaceSSID
|
|
|
|
iface.Bssid = ifaceBssid
|
|
|
|
iface.Network = ifaceNetwork
|
|
|
|
iface.Encryption = ifaceEnc
|
|
|
|
iface.Key = ifaceKey
|
2018-09-24 17:38:17 +02:00
|
|
|
|
2018-10-05 16:12:07 +02:00
|
|
|
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)
|
2018-09-24 17:38:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreate(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
|
|
|
|
iface := NewUCIWirelessInterface()
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Name = ifaceName
|
|
|
|
iface.Device = ifaceDevice
|
|
|
|
iface.Mode = ifaceMode
|
|
|
|
iface.Ssid = ifaceSSID
|
|
|
|
iface.Bssid = ifaceBssid
|
|
|
|
iface.Network = ifaceNetwork
|
|
|
|
iface.Encryption = ifaceEnc
|
|
|
|
iface.Key = ifaceKey
|
2018-09-24 17:38:17 +02:00
|
|
|
|
|
|
|
if iface.Create(uci).ReturnCode != 0 {
|
|
|
|
t.Fatalf("UCIWirelessInterface.Create() failed !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUpdate(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
|
|
|
|
iface := NewUCIWirelessInterface()
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Name = ifaceName
|
2018-09-24 17:38:17 +02:00
|
|
|
iface.Index = 1
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Device = ifaceDevice
|
|
|
|
iface.SysDevName = ifaceSysDevName
|
|
|
|
iface.Mode = ifaceMode
|
|
|
|
iface.Ssid = ifaceSSID
|
|
|
|
iface.Bssid = ifaceBssid
|
|
|
|
iface.Network = ifaceNetwork
|
|
|
|
iface.Encryption = ifaceEnc
|
|
|
|
iface.Key = ifaceKey
|
2018-09-24 17:38:17 +02:00
|
|
|
|
|
|
|
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()
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Name = ifaceName
|
2018-09-24 17:38:17 +02:00
|
|
|
iface.Index = 1
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Device = ifaceDevice
|
|
|
|
iface.SysDevName = ifaceSysDevName
|
|
|
|
iface.Mode = ifaceMode
|
|
|
|
iface.Ssid = ifaceSSID
|
|
|
|
iface.Bssid = ifaceBssid
|
|
|
|
iface.Network = ifaceNetwork
|
|
|
|
iface.Encryption = ifaceEnc
|
|
|
|
iface.Key = ifaceKey
|
2018-09-24 17:38:17 +02:00
|
|
|
|
|
|
|
if iface.Delete(uci).ReturnCode != 0 {
|
|
|
|
t.Fatalf("UCIWirelessInterface.Delete() failed !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConnect(t *testing.T) {
|
|
|
|
|
|
|
|
exec := createMockExecutor("", "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
|
|
|
|
iface := NewUCIWirelessInterface()
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Name = ifaceName
|
2018-09-24 17:38:17 +02:00
|
|
|
iface.Index = 1
|
2018-10-08 15:39:16 +02:00
|
|
|
iface.Device = ifaceDevice
|
|
|
|
iface.SysDevName = ifaceSysDevName
|
|
|
|
iface.Mode = ifaceMode
|
|
|
|
iface.Ssid = ifaceSSID
|
|
|
|
iface.Bssid = ifaceBssid
|
|
|
|
iface.Network = ifaceNetwork
|
|
|
|
iface.Encryption = ifaceEnc
|
|
|
|
iface.Key = ifaceKey
|
2018-09-24 17:38:17 +02:00
|
|
|
|
|
|
|
wifiCell := NewWifiCell("PyxisWifi", "01:01:01:01:01", "psk")
|
|
|
|
|
|
|
|
if iface.Connect(uci, wifiCell, "Toto").ReturnCode != 0 {
|
|
|
|
t.Fatalf("UCIWirelessInterface.Delete() failed !")
|
|
|
|
}
|
|
|
|
}
|