github.com/homburg/packer@v0.6.1-0.20140528012651-1dcaf1716848/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) != 1 {
    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-add" {
    47  		t.Fatal("bad call")
    48  	}
    49  	if driver.PrlctlCalls[0][3] != "fdd" {
    50  		t.Fatal("bad call")
    51  	}
    52  }
    53  
    54  func TestStepAttachFloppy_noFloppy(t *testing.T) {
    55  	state := testState(t)
    56  	step := new(StepAttachFloppy)
    57  
    58  	driver := state.Get("driver").(*DriverMock)
    59  
    60  	// Test the run
    61  	if action := step.Run(state); action != multistep.ActionContinue {
    62  		t.Fatalf("bad action: %#v", action)
    63  	}
    64  	if _, ok := state.GetOk("error"); ok {
    65  		t.Fatal("should NOT have error")
    66  	}
    67  
    68  	if len(driver.PrlctlCalls) > 0 {
    69  		t.Fatal("should not call prlctl")
    70  	}
    71  }