github.com/homburg/packer@v0.6.1-0.20140528012651-1dcaf1716848/builder/parallels/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.PrlctlCalls) != 0 { 30 t.Fatalf("bad: %#v", driver.PrlctlCalls) 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 detached 52 if len(driver.PrlctlCalls) != 1 { 53 t.Fatalf("bad: %#v", driver.PrlctlCalls) 54 } 55 if driver.PrlctlCalls[0][2] != "--device-set" { 56 t.Fatalf("bad: %#v", driver.PrlctlCalls) 57 } 58 if driver.PrlctlCalls[0][3] != "cdrom0" { 59 t.Fatalf("bad: %#v", driver.PrlctlCalls) 60 } 61 if driver.PrlctlCalls[0][5] != "Default CD/DVD-ROM" { 62 t.Fatalf("bad: %#v", driver.PrlctlCalls) 63 } 64 } 65 66 func TestStepRemoveDevices_floppyPath(t *testing.T) { 67 state := testState(t) 68 step := new(StepRemoveDevices) 69 70 state.Put("floppy_path", "foo") 71 state.Put("vmName", "foo") 72 73 driver := state.Get("driver").(*DriverMock) 74 75 // Test the run 76 if action := step.Run(state); action != multistep.ActionContinue { 77 t.Fatalf("bad action: %#v", action) 78 } 79 if _, ok := state.GetOk("error"); ok { 80 t.Fatal("should NOT have error") 81 } 82 83 // Test that both were removed 84 if len(driver.PrlctlCalls) != 1 { 85 t.Fatalf("bad: %#v", driver.PrlctlCalls) 86 } 87 if driver.PrlctlCalls[0][2] != "--device-del" { 88 t.Fatalf("bad: %#v", driver.PrlctlCalls) 89 } 90 if driver.PrlctlCalls[0][3] != "fdd0" { 91 t.Fatalf("bad: %#v", driver.PrlctlCalls) 92 } 93 }