2018-09-19 14:39:00 +02:00
|
|
|
package openwrt
|
|
|
|
|
|
|
|
import (
|
2018-09-20 10:59:11 +02:00
|
|
|
"fmt"
|
2018-09-19 14:39:00 +02:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2018-09-20 10:59:11 +02:00
|
|
|
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 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 ...")
|
|
|
|
}
|
|
|
|
}
|
2018-09-19 14:39:00 +02:00
|
|
|
|
2018-09-20 10:59:11 +02:00
|
|
|
func TestUCICommit(t *testing.T) {
|
|
|
|
exec := createMockExecutor("", "", 0)
|
|
|
|
uci := NewUCIWithExecutor(exec)
|
|
|
|
res := uci.Commit()
|
2018-09-19 15:22:51 +02:00
|
|
|
if res.ReturnCode != 0 {
|
2018-09-20 10:59:11 +02:00
|
|
|
t.Error("Bad Return Code !")
|
|
|
|
}
|
|
|
|
if res.Stdout != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stdout is not empty ...")
|
2018-09-19 14:39:00 +02:00
|
|
|
}
|
2018-09-20 10:59:11 +02:00
|
|
|
if res.Stderr != "" {
|
|
|
|
fmt.Printf("[%s] - ", res.Stdout)
|
|
|
|
t.Error("Stderr is not empty ...")
|
|
|
|
}
|
|
|
|
}
|
2018-09-19 14:39:00 +02:00
|
|
|
|
2018-09-20 10:59:11 +02:00
|
|
|
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-09-19 14:39:00 +02:00
|
|
|
}
|