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