owrt/uci_test.go

101 lines
2.2 KiB
Go
Raw Normal View History

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