2018-10-24 10:26:11 +02:00
|
|
|
package owrt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-29 11:19:40 +01:00
|
|
|
"io/ioutil"
|
2018-10-24 10:26:11 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUCIAdd(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
res := uci.Add("wireless", "test")
|
|
|
|
if res.ReturnCode != 0 {
|
|
|
|
t.Error("Bad Return Code !")
|
|
|
|
}
|
|
|
|
if res.Stdout != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stdout is not empty ...")
|
|
|
|
}
|
|
|
|
if res.Stderr != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stderr is not empty ...")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUCIAddFailed(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "BigError", 3)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
res := uci.Add("wireless", "test")
|
|
|
|
if res.ReturnCode != 3 {
|
|
|
|
t.Error("Bad Return Code !")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUCIDelete(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
res := uci.Delete("wireless.@wifi-iface[1]")
|
|
|
|
if res.ReturnCode != 0 {
|
|
|
|
t.Error("Bad Return Code !")
|
|
|
|
}
|
|
|
|
if res.Stdout != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stdout is not empty ...")
|
|
|
|
}
|
|
|
|
if res.Stderr != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stderr is not empty ...")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUCISet(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
res := uci.Set("wireless.@wifi-iface[1].network", "OrionNetwork")
|
|
|
|
if res.ReturnCode != 0 {
|
|
|
|
t.Error("Bad Return Code !")
|
|
|
|
}
|
|
|
|
if res.Stdout != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stdout is not empty ...")
|
|
|
|
}
|
|
|
|
if res.Stderr != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stderr is not empty ...")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUCICommit(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
res := uci.Commit()
|
|
|
|
if res.ReturnCode != 0 {
|
|
|
|
t.Error("Bad Return Code !")
|
|
|
|
}
|
|
|
|
if res.Stdout != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stdout is not empty ...")
|
|
|
|
}
|
|
|
|
if res.Stderr != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stderr is not empty ...")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUCIReload(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
res := uci.Reload()
|
|
|
|
if res.ReturnCode != 0 {
|
|
|
|
t.Error("Bad Return Code !")
|
|
|
|
}
|
|
|
|
if res.Stdout != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stdout is not empty ...")
|
|
|
|
}
|
|
|
|
if res.Stderr != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stderr is not empty ...")
|
|
|
|
}
|
|
|
|
}
|
2018-10-29 11:19:40 +01:00
|
|
|
|
|
|
|
func TestGetWifiIfaceBySSID(t *testing.T) {
|
|
|
|
config, err := ioutil.ReadFile("./testdata/uci_show_wireless_2_cards.txt")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
exec := createMockExecutor(string(config), "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
uci.LoadWirelessConf()
|
|
|
|
wifi := uci.GetWifiIfaceBySSID("Pyxis2")
|
|
|
|
fmt.Printf("%s\n", wifi.Ssid)
|
|
|
|
if g, e := wifi.Ssid, "Pyxis2"; g != e {
|
|
|
|
t.Fatalf("Wifi SSID have to be [%s] and we have [%s]", e, g)
|
|
|
|
}
|
|
|
|
}
|