github.com/rothwerx/packer@v0.9.0/builder/virtualbox/common/step_remove_devices_test.go (about) 1 package common 2 3 import ( 4 "github.com/mitchellh/multistep" 5 "testing" 6 ) 7 8 func TestStepRemoveDevices_impl(t *testing.T) { 9 var _ multistep.Step = new(StepRemoveDevices) 10 } 11 12 func TestStepRemoveDevices(t *testing.T) { 13 state := testState(t) 14 step := new(StepRemoveDevices) 15 16 state.Put("vmName", "foo") 17 18 driver := state.Get("driver").(*DriverMock) 19 20 // Test the run 21 if action := step.Run(state); action != multistep.ActionContinue { 22 t.Fatalf("bad action: %#v", action) 23 } 24 if _, ok := state.GetOk("error"); ok { 25 t.Fatal("should NOT have error") 26 } 27 28 // Test that ISO was removed 29 if len(driver.VBoxManageCalls) != 0 { 30 t.Fatalf("bad: %#v", driver.VBoxManageCalls) 31 } 32 } 33 34 func TestStepRemoveDevices_attachedIso(t *testing.T) { 35 state := testState(t) 36 step := new(StepRemoveDevices) 37 38 state.Put("attachedIso", true) 39 state.Put("vmName", "foo") 40 41 driver := state.Get("driver").(*DriverMock) 42 43 // Test the run 44 if action := step.Run(state); action != multistep.ActionContinue { 45 t.Fatalf("bad action: %#v", action) 46 } 47 if _, ok := state.GetOk("error"); ok { 48 t.Fatal("should NOT have error") 49 } 50 51 // Test that ISO was removed 52 if len(driver.VBoxManageCalls) != 1 { 53 t.Fatalf("bad: %#v", driver.VBoxManageCalls) 54 } 55 if driver.VBoxManageCalls[0][3] != "IDE Controller" { 56 t.Fatalf("bad: %#v", driver.VBoxManageCalls) 57 } 58 } 59 60 func TestStepRemoveDevices_attachedIsoOnSata(t *testing.T) { 61 state := testState(t) 62 step := new(StepRemoveDevices) 63 64 state.Put("attachedIso", true) 65 state.Put("attachedIsoOnSata", true) 66 state.Put("vmName", "foo") 67 68 driver := state.Get("driver").(*DriverMock) 69 70 // Test the run 71 if action := step.Run(state); action != multistep.ActionContinue { 72 t.Fatalf("bad action: %#v", action) 73 } 74 if _, ok := state.GetOk("error"); ok { 75 t.Fatal("should NOT have error") 76 } 77 78 // Test that ISO was removed 79 if len(driver.VBoxManageCalls) != 1 { 80 t.Fatalf("bad: %#v", driver.VBoxManageCalls) 81 } 82 if driver.VBoxManageCalls[0][3] != "SATA Controller" { 83 t.Fatalf("bad: %#v", driver.VBoxManageCalls) 84 } 85 } 86 87 func TestStepRemoveDevices_floppyPath(t *testing.T) { 88 state := testState(t) 89 step := new(StepRemoveDevices) 90 91 state.Put("floppy_path", "foo") 92 state.Put("vmName", "foo") 93 94 driver := state.Get("driver").(*DriverMock) 95 96 // Test the run 97 if action := step.Run(state); action != multistep.ActionContinue { 98 t.Fatalf("bad action: %#v", action) 99 } 100 if _, ok := state.GetOk("error"); ok { 101 t.Fatal("should NOT have error") 102 } 103 104 // Test that both were removed 105 if len(driver.VBoxManageCalls) != 2 { 106 t.Fatalf("bad: %#v", driver.VBoxManageCalls) 107 } 108 if driver.VBoxManageCalls[0][3] != "Floppy Controller" { 109 t.Fatalf("bad: %#v", driver.VBoxManageCalls) 110 } 111 if driver.VBoxManageCalls[1][3] != "Floppy Controller" { 112 t.Fatalf("bad: %#v", driver.VBoxManageCalls) 113 } 114 }