Move qemu init for tests to separate function
This commit is contained in:
parent
5c31812089
commit
667c42a8c6
@ -85,10 +85,11 @@ type QemuSystem struct {
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return
|
||||
}
|
||||
q = &QemuSystem{}
|
||||
q.arch = arch
|
||||
|
||||
if _, err = os.Stat(kernel.Path); err != nil {
|
||||
|
@ -65,18 +65,24 @@ func TestGetFreeAddrPort(t *testing.T) {
|
||||
ln.Close()
|
||||
}
|
||||
|
||||
func TestQemuSystemCommand(t *testing.T) {
|
||||
func startTestQemu() (q *QemuSystem, err error) {
|
||||
// FIXME hardcoded kernel path
|
||||
kernel := Kernel{Name: "Host kernel", Path: "/boot/vmlinuz-4.18.8"}
|
||||
// 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 {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = qemu.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
if err = q.Start(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func TestQemuSystemCommand(t *testing.T) {
|
||||
qemu, err := startTestQemu()
|
||||
defer qemu.Stop()
|
||||
|
||||
output, err := qemu.Command("root", "cat /etc/shadow")
|
||||
|
Loading…
Reference in New Issue
Block a user