2018-11-07 11:52:59 +00:00
|
|
|
package pkg
|
|
|
|
|
|
|
|
import (
|
2018-11-18 21:49:11 +00:00
|
|
|
"git.xdrm.io/go/nix-amer/internal/exec"
|
2018-11-07 11:52:59 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2018-11-11 20:38:16 +00:00
|
|
|
/////////////////// MOCKUP START ///////////////////
|
|
|
|
type MockupCommand struct {
|
|
|
|
Out []byte
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c MockupCommand) Run() error { return c.Err }
|
|
|
|
func (c MockupCommand) Output() ([]byte, error) { return c.Out, c.Err }
|
|
|
|
|
|
|
|
type MockupExecutor struct {
|
|
|
|
Out []byte
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d MockupExecutor) Command(cmd string, args ...string) exec.Command {
|
|
|
|
return &MockupCommand{Out: d.Out, Err: d.Err}
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////// MOCKUP END ///////////////////
|
|
|
|
|
2018-11-10 11:37:31 +00:00
|
|
|
func TestUnknownManager(t *testing.T) {
|
2018-11-07 11:52:59 +00:00
|
|
|
|
2018-11-11 20:38:16 +00:00
|
|
|
execctx := new(MockupExecutor)
|
|
|
|
execctx.Err = nil
|
|
|
|
execctx.Out = []byte{}
|
|
|
|
|
|
|
|
_, err := Load("apt-put", execctx)
|
2018-11-10 11:37:31 +00:00
|
|
|
if err != ErrUnknownManager {
|
|
|
|
t.Errorf("expected <%s>, got <%s>", ErrUnknownManager, err)
|
2018-11-07 11:52:59 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-11-10 11:37:31 +00:00
|
|
|
func TestKnownManager(t *testing.T) {
|
2018-11-11 20:38:16 +00:00
|
|
|
execctx := new(MockupExecutor)
|
|
|
|
execctx.Err = nil
|
|
|
|
execctx.Out = []byte{}
|
2018-11-07 11:52:59 +00:00
|
|
|
|
2018-11-11 20:38:16 +00:00
|
|
|
_, err := Load("apt-get", execctx)
|
2018-11-07 11:52:59 +00:00
|
|
|
if err != nil {
|
2018-11-10 11:37:31 +00:00
|
|
|
t.Errorf("unexpected error <%s>", err)
|
2018-11-07 11:52:59 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|