owrt/uci_test.go

117 lines
2.7 KiB
Go

package owrt
import (
"fmt"
"io/ioutil"
"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 ...")
}
}
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)
}
}