github.com/sneal/packer@v0.5.2/builder/virtualbox/common/step_remove_devices_test.go (about)

     1  package common
     2  
     3  import (
     4  	"github.com/mitchellh/multistep"
     5  	"testing"
     6  )
     7  
     8  func TestStepRemoveDevices_impl(t *testing.T) {
     9  	var _ multistep.Step = new(StepRemoveDevices)
    10  }
    11  
    12  func TestStepRemoveDevices(t *testing.T) {
    13  	state := testState(t)
    14  	step := new(StepRemoveDevices)
    15  
    16  	state.Put("vmName", "foo")
    17  
    18  	driver := state.Get("driver").(*DriverMock)
    19  
    20  	// Test the run
    21  	if action := step.Run(state); action != multistep.ActionContinue {
    22  		t.Fatalf("bad action: %#v", action)
    23  	}
    24  	if _, ok := state.GetOk("error"); ok {
    25  		t.Fatal("should NOT have error")
    26  	}
    27  
    28  	// Test that ISO was removed
    29  	if len(driver.VBoxManageCalls) != 0 {
    30  		t.Fatalf("bad: %#v", driver.VBoxManageCalls)
    31  	}
    32  }
    33  
    34  func TestStepRemoveDevices_attachedIso(t *testing.T) {
    35  	state := testState(t)
    36  	step := new(StepRemoveDevices)
    37  
    38  	state.Put("attachedIso", true)
    39  	state.Put("vmName", "foo")
    40  
    41  	driver := state.Get("driver").(*DriverMock)
    42  
    43  	// Test the run
    44  	if action := step.Run(state); action != multistep.ActionContinue {
    45  		t.Fatalf("bad action: %#v", action)
    46  	}
    47  	if _, ok := state.GetOk("error"); ok {
    48  		t.Fatal("should NOT have error")
    49  	}
    50  
    51  	// Test that ISO was removed
    52  	if len(driver.VBoxManageCalls) != 1 {
    53  		t.Fatalf("bad: %#v", driver.VBoxManageCalls)
    54  	}
    55  	if driver.VBoxManageCalls[0][3] != "IDE Controller" {
    56  		t.Fatalf("bad: %#v", driver.VBoxManageCalls)
    57  	}
    58  }
    59  
    60  func TestStepRemoveDevices_floppyPath(t *testing.T) {
    61  	state := testState(t)
    62  	step := new(StepRemoveDevices)
    63  
    64  	state.Put("floppy_path", "foo")
    65  	state.Put("vmName", "foo")
    66  
    67  	driver := state.Get("driver").(*DriverMock)
    68  
    69  	// Test the run
    70  	if action := step.Run(state); action != multistep.ActionContinue {
    71  		t.Fatalf("bad action: %#v", action)
    72  	}
    73  	if _, ok := state.GetOk("error"); ok {
    74  		t.Fatal("should NOT have error")
    75  	}
    76  
    77  	// Test that both were removed
    78  	if len(driver.VBoxManageCalls) != 1 {
    79  		t.Fatalf("bad: %#v", driver.VBoxManageCalls)
    80  	}
    81  	if driver.VBoxManageCalls[0][3] != "Floppy Controller" {
    82  		t.Fatalf("bad: %#v", driver.VBoxManageCalls)
    83  	}
    84  }