This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/openwrt/uci_test.go

49 lines
888 B
Go
Raw Normal View History

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)
}
}