2013-12-22 11:10:11 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 19:03:49 -05:00
|
|
|
"context"
|
2013-12-22 11:10:11 -05:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"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 11:10:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepAttachFloppy_impl(t *testing.T) {
|
|
|
|
var _ multistep.Step = new(StepAttachFloppy)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepAttachFloppy(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepAttachFloppy)
|
|
|
|
|
|
|
|
// Create a temporary file for our floppy file
|
|
|
|
tf, err := ioutil.TempFile("", "packer")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
tf.Close()
|
|
|
|
defer os.Remove(tf.Name())
|
|
|
|
|
|
|
|
state.Put("floppy_path", tf.Name())
|
|
|
|
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 11:10:11 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
2020-03-03 23:58:09 -05:00
|
|
|
if driver.RemoveFloppyControllersVM == "" {
|
|
|
|
t.Fatal("RemoveFloppyControllers was not called")
|
|
|
|
}
|
|
|
|
|
2013-12-22 11:10:11 -05:00
|
|
|
if len(driver.VBoxManageCalls) != 2 {
|
|
|
|
t.Fatal("not enough calls to VBoxManage")
|
|
|
|
}
|
|
|
|
if driver.VBoxManageCalls[0][0] != "storagectl" {
|
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
|
|
|
if driver.VBoxManageCalls[1][0] != "storageattach" {
|
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the cleanup
|
|
|
|
step.Cleanup(state)
|
|
|
|
if driver.VBoxManageCalls[2][0] != "storageattach" {
|
|
|
|
t.Fatal("bad call")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepAttachFloppy_noFloppy(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepAttachFloppy)
|
|
|
|
|
|
|
|
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 11:10:11 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(driver.VBoxManageCalls) > 0 {
|
|
|
|
t.Fatal("should not call vboxmanage")
|
|
|
|
}
|
|
|
|
}
|