Commit fbd20dff authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/virtualbox/common: StepRemoveDevices

parent b65559d8
package iso
package common
import (
"fmt"
"github.com/mitchellh/multistep"
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
)
......@@ -11,12 +10,15 @@ import (
// machine that we may have added.
//
// Uses:
// driver Driver
// ui packer.Ui
// vmName string
//
// Produces:
type stepRemoveDevices struct{}
type StepRemoveDevices struct{}
func (s *stepRemoveDevices) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(vboxcommon.Driver)
func (s *StepRemoveDevices) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
vmName := state.Get("vmName").(string)
......@@ -56,5 +58,5 @@ func (s *stepRemoveDevices) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionContinue
}
func (s *stepRemoveDevices) Cleanup(state multistep.StateBag) {
func (s *StepRemoveDevices) Cleanup(state multistep.StateBag) {
}
package common
import (
"github.com/mitchellh/multistep"
"testing"
)
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
if action := step.Run(state); action != multistep.ActionContinue {
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] != "IDE Controller" {
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
}
}
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
if action := step.Run(state); action != multistep.ActionContinue {
t.Fatalf("bad action: %#v", action)
}
if _, ok := state.GetOk("error"); ok {
t.Fatal("should NOT have error")
}
// Test that both were removed
if len(driver.VBoxManageCalls) != 2 {
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
}
if driver.VBoxManageCalls[0][3] != "Floppy Controller" {
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
}
if driver.VBoxManageCalls[1][3] != "IDE Controller" {
t.Fatalf("bad: %#v", driver.VBoxManageCalls)
}
}
......@@ -326,7 +326,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Command: b.config.ShutdownCommand,
Timeout: b.config.ShutdownTimeout,
},
new(stepRemoveDevices),
new(vboxcommon.StepRemoveDevices),
new(stepExport),
}
......
......@@ -79,8 +79,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Command: b.config.ShutdownCommand,
Timeout: b.config.ShutdownTimeout,
},
new(vboxcommon.StepRemoveDevices),
/*
new(stepRemoveDevices),
new(stepExport),
*/
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment