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