49 lines
888 B
Go
49 lines
888 B
Go
|
package openwrt
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"strings"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
var retCode int
|
||
|
var retStdout string
|
||
|
var retStderr string
|
||
|
|
||
|
type UCI struct {
|
||
|
exec Executor
|
||
|
}
|
||
|
|
||
|
func (u *UCI) Run(command string, args []string) (stdout string, stderr string, exit int, err error) {
|
||
|
return u.exec.Run(command, args)
|
||
|
}
|
||
|
|
||
|
func NewUCI(exec Executor) *UCI {
|
||
|
return &UCI{exec}
|
||
|
}
|
||
|
|
||
|
type Executor interface {
|
||
|
Run(command string, args []string) (stdout string, stderr string, exit int, err error)
|
||
|
}
|
||
|
|
||
|
type fakeExecutor struct{}
|
||
|
|
||
|
func (e *fakeExecutor) Run(command string, args []string) (stdout string, stderr string, exit int, err error) {
|
||
|
log.Printf("executing '%s %s'", command, strings.Join(args, " "))
|
||
|
return "", "", 0, nil
|
||
|
}
|
||
|
|
||
|
func TestUciAdd(t *testing.T) {
|
||
|
|
||
|
retCode = 0
|
||
|
retStdout = "OK"
|
||
|
retStderr = ""
|
||
|
|
||
|
// Return 0 run !
|
||
|
res := UciAdd("wireless", "test")
|
||
|
if res.returnCode != 0 {
|
||
|
t.Error(res.errors)
|
||
|
}
|
||
|
|
||
|
}
|