github.com/rothwerx/packer@v0.9.0/builder/parallels/common/step_attach_floppy_test.go (about) 1 package common 2 3 import ( 4 "github.com/mitchellh/multistep" 5 "io/ioutil" 6 "os" 7 "testing" 8 ) 9 10 func TestStepAttachFloppy_impl(t *testing.T) { 11 var _ multistep.Step = new(StepAttachFloppy) 12 } 13 14 func TestStepAttachFloppy(t *testing.T) { 15 state := testState(t) 16 step := new(StepAttachFloppy) 17 18 // Create a temporary file for our floppy file 19 tf, err := ioutil.TempFile("", "packer") 20 if err != nil { 21 t.Fatalf("err: %s", err) 22 } 23 tf.Close() 24 defer os.Remove(tf.Name()) 25 26 state.Put("floppy_path", tf.Name()) 27 state.Put("vmName", "foo") 28 29 driver := state.Get("driver").(*DriverMock) 30 31 // Test the run 32 if action := step.Run(state); action != multistep.ActionContinue { 33 t.Fatalf("bad action: %#v", action) 34 } 35 if _, ok := state.GetOk("error"); ok { 36 t.Fatal("should NOT have error") 37 } 38 39 if len(driver.PrlctlCalls) != 2 { 40 t.Fatal("not enough calls to prlctl") 41 } 42 43 if driver.PrlctlCalls[0][0] != "set" { 44 t.Fatal("bad call") 45 } 46 if driver.PrlctlCalls[0][2] != "--device-del" { 47 t.Fatal("bad call") 48 } 49 if driver.PrlctlCalls[0][3] != "fdd0" { 50 t.Fatal("bad call") 51 } 52 53 if driver.PrlctlCalls[1][0] != "set" { 54 t.Fatal("bad call") 55 } 56 if driver.PrlctlCalls[1][2] != "--device-add" { 57 t.Fatal("bad call") 58 } 59 if driver.PrlctlCalls[1][3] != "fdd" { 60 t.Fatal("bad call") 61 } 62 if driver.PrlctlCalls[1][6] != "--connect" { 63 t.Fatal("bad call") 64 } 65 } 66 67 func TestStepAttachFloppy_noFloppy(t *testing.T) { 68 state := testState(t) 69 step := new(StepAttachFloppy) 70 71 driver := state.Get("driver").(*DriverMock) 72 73 // Test the run 74 if action := step.Run(state); action != multistep.ActionContinue { 75 t.Fatalf("bad action: %#v", action) 76 } 77 if _, ok := state.GetOk("error"); ok { 78 t.Fatal("should NOT have error") 79 } 80 81 if len(driver.PrlctlCalls) > 0 { 82 t.Fatal("should not call prlctl") 83 } 84 }