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