2013-12-22 12:54:00 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 19:03:49 -05:00
|
|
|
"context"
|
2013-12-22 12:54:00 -05:00
|
|
|
"testing"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2018-01-22 18:32:33 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2013-12-22 12:54:00 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepRemoveDevices_impl(t *testing.T) {
|
|
|
|
var _ multistep.Step = new(StepRemoveDevices)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepRemoveDevices(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepRemoveDevices)
|
|
|
|
|
|
|
|
state.Put("vmName", "foo")
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2013-12-22 12:54:00 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
2013-12-22 20:08:07 -05:00
|
|
|
// Test that ISO was removed
|
|
|
|
if len(driver.VBoxManageCalls) != 0 {
|
|
|
|
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepRemoveDevices_attachedIso(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepRemoveDevices)
|
|
|
|
|
|
|
|
state.Put("attachedIso", true)
|
|
|
|
state.Put("vmName", "foo")
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2013-12-22 20:08:07 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
2013-12-22 12:54:00 -05:00
|
|
|
// Test that ISO was removed
|
|
|
|
if len(driver.VBoxManageCalls) != 1 {
|
|
|
|
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
|
|
|
|
}
|
|
|
|
if driver.VBoxManageCalls[0][3] != "IDE Controller" {
|
|
|
|
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 21:14:24 -04:00
|
|
|
func TestStepRemoveDevices_attachedIsoOnSata(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepRemoveDevices)
|
|
|
|
|
|
|
|
state.Put("attachedIso", true)
|
|
|
|
state.Put("attachedIsoOnSata", true)
|
|
|
|
state.Put("vmName", "foo")
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2014-05-23 21:14:24 -04:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that ISO was removed
|
|
|
|
if len(driver.VBoxManageCalls) != 1 {
|
|
|
|
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
|
|
|
|
}
|
|
|
|
if driver.VBoxManageCalls[0][3] != "SATA Controller" {
|
|
|
|
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-22 12:54:00 -05:00
|
|
|
func TestStepRemoveDevices_floppyPath(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepRemoveDevices)
|
|
|
|
|
|
|
|
state.Put("floppy_path", "foo")
|
|
|
|
state.Put("vmName", "foo")
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2013-12-22 12:54:00 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that both were removed
|
2015-06-08 23:31:53 -04:00
|
|
|
if len(driver.VBoxManageCalls) != 2 {
|
2013-12-22 12:54:00 -05:00
|
|
|
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
|
|
|
|
}
|
|
|
|
if driver.VBoxManageCalls[0][3] != "Floppy Controller" {
|
|
|
|
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
|
|
|
|
}
|
2015-06-08 23:31:53 -04:00
|
|
|
if driver.VBoxManageCalls[1][3] != "Floppy Controller" {
|
|
|
|
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
|
|
|
|
}
|
2013-12-22 12:54:00 -05:00
|
|
|
}
|