github.com/sneal/packer@v0.5.2/builder/virtualbox/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.VBoxManageCalls) != 2 {
    40  		t.Fatal("not enough calls to VBoxManage")
    41  	}
    42  	if driver.VBoxManageCalls[0][0] != "storagectl" {
    43  		t.Fatal("bad call")
    44  	}
    45  	if driver.VBoxManageCalls[1][0] != "storageattach" {
    46  		t.Fatal("bad call")
    47  	}
    48  
    49  	// Test the cleanup
    50  	step.Cleanup(state)
    51  	if driver.VBoxManageCalls[2][0] != "storageattach" {
    52  		t.Fatal("bad call")
    53  	}
    54  }
    55  
    56  func TestStepAttachFloppy_noFloppy(t *testing.T) {
    57  	state := testState(t)
    58  	step := new(StepAttachFloppy)
    59  
    60  	driver := state.Get("driver").(*DriverMock)
    61  
    62  	// Test the run
    63  	if action := step.Run(state); action != multistep.ActionContinue {
    64  		t.Fatalf("bad action: %#v", action)
    65  	}
    66  	if _, ok := state.GetOk("error"); ok {
    67  		t.Fatal("should NOT have error")
    68  	}
    69  
    70  	if len(driver.VBoxManageCalls) > 0 {
    71  		t.Fatal("should not call vboxmanage")
    72  	}
    73  }