Adding Opkg support for system interactions
This commit is contained in:
parent
db024d3c05
commit
6e84372169
|
@ -28,8 +28,7 @@ func NewSystemWithExecutor(exec Executor) *System {
|
||||||
}
|
}
|
||||||
|
|
||||||
// sysRun, private method to run the UCI command
|
// sysRun, private method to run the UCI command
|
||||||
func (s *System) sysRun(param ...string) *SysAction {
|
func (s *System) sysRun(cmd string, param ...string) *SysAction {
|
||||||
cmd := param[0]
|
|
||||||
res := s.exec.Run(cmd, param...)
|
res := s.exec.Run(cmd, param...)
|
||||||
return &SysAction{res, fmt.Sprintf("%s %s", cmd, param)}
|
return &SysAction{res, fmt.Sprintf("%s %s", cmd, param)}
|
||||||
}
|
}
|
||||||
|
@ -39,3 +38,9 @@ func (s *System) Service(name string, action string) *SysAction {
|
||||||
cmd := fmt.Sprintf("/etc/init.d/%s", name)
|
cmd := fmt.Sprintf("/etc/init.d/%s", name)
|
||||||
return s.sysRun(cmd, action)
|
return s.sysRun(cmd, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Opkg provides an interface to system command opkg
|
||||||
|
// useful for package installation or system update
|
||||||
|
func (s *System) Opkg(params ...string) *SysAction {
|
||||||
|
return s.sysRun("opkg", params...)
|
||||||
|
}
|
||||||
|
|
|
@ -21,3 +21,33 @@ func TestService(t *testing.T) {
|
||||||
t.Error("Stderr is not empty ...")
|
t.Error("Stderr is not empty ...")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOpkg(t *testing.T) {
|
||||||
|
exec := createMockExecutor("", "", 0)
|
||||||
|
sys := NewSystemWithExecutor(exec)
|
||||||
|
res := sys.Opkg("update")
|
||||||
|
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 ...")
|
||||||
|
}
|
||||||
|
|
||||||
|
res = sys.Opkg("install", "ip")
|
||||||
|
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 ...")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue