1
0

Move qemu init for tests to separate function

This commit is contained in:
dump_stack() 2018-09-20 23:45:46 +00:00
parent 5c31812089
commit 667c42a8c6
2 changed files with 13 additions and 6 deletions

View File

@ -85,10 +85,11 @@ type QemuSystem struct {
} }
// NewQemuSystem constructor // NewQemuSystem constructor
func NewQemuSystem(arch arch, kernel Kernel, drivePath string) (q QemuSystem, err error) { func NewQemuSystem(arch arch, kernel Kernel, drivePath string) (q *QemuSystem, err error) {
if _, err = exec.LookPath("qemu-system-" + string(arch)); err != nil { if _, err = exec.LookPath("qemu-system-" + string(arch)); err != nil {
return return
} }
q = &QemuSystem{}
q.arch = arch q.arch = arch
if _, err = os.Stat(kernel.Path); err != nil { if _, err = os.Stat(kernel.Path); err != nil {

View File

@ -65,18 +65,24 @@ func TestGetFreeAddrPort(t *testing.T) {
ln.Close() ln.Close()
} }
func TestQemuSystemCommand(t *testing.T) { func startTestQemu() (q *QemuSystem, err error) {
// FIXME hardcoded kernel path // FIXME hardcoded kernel path
kernel := Kernel{Name: "Host kernel", Path: "/boot/vmlinuz-4.18.8"} kernel := Kernel{Name: "Host kernel", Path: "/boot/vmlinuz-4.18.8"}
// FIXME hardcoded qcow2 path // FIXME hardcoded qcow2 path
qemu, err := NewQemuSystem(X86_64, kernel, "/home/user/qemu/sid.img") q, err = NewQemuSystem(X86_64, kernel, "/home/user/qemu/sid.img")
if err != nil { if err != nil {
t.Fatal(err) return
} }
if err = qemu.Start(); err != nil { if err = q.Start(); err != nil {
t.Fatal(err) return
} }
return
}
func TestQemuSystemCommand(t *testing.T) {
qemu, err := startTestQemu()
defer qemu.Stop() defer qemu.Stop()
output, err := qemu.Command("root", "cat /etc/shadow") output, err := qemu.Command("root", "cat /etc/shadow")