diff --git a/system.go b/system.go index a701a53..f58f758 100644 --- a/system.go +++ b/system.go @@ -28,8 +28,7 @@ func NewSystemWithExecutor(exec Executor) *System { } // sysRun, private method to run the UCI command -func (s *System) sysRun(param ...string) *SysAction { - cmd := param[0] +func (s *System) sysRun(cmd string, param ...string) *SysAction { res := s.exec.Run(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) 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...) +} diff --git a/system_test.go b/system_test.go index 9920056..666ef2f 100644 --- a/system_test.go +++ b/system_test.go @@ -21,3 +21,33 @@ func TestService(t *testing.T) { 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 ...") + } +}