github.com/mitchellh/packer@v1.3.2/builder/virtualbox/common/step_export_test.go (about)

     1  package common
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/packer/helper/multistep"
     8  )
     9  
    10  func TestStepExport_impl(t *testing.T) {
    11  	var _ multistep.Step = new(StepExport)
    12  }
    13  
    14  func TestStepExport(t *testing.T) {
    15  	state := testState(t)
    16  	step := new(StepExport)
    17  
    18  	state.Put("vmName", "foo")
    19  
    20  	driver := state.Get("driver").(*DriverMock)
    21  
    22  	// Test the run
    23  	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
    24  		t.Fatalf("bad action: %#v", action)
    25  	}
    26  	if _, ok := state.GetOk("error"); ok {
    27  		t.Fatal("should NOT have error")
    28  	}
    29  
    30  	// Test output state
    31  	if _, ok := state.GetOk("exportPath"); !ok {
    32  		t.Fatal("should set exportPath")
    33  	}
    34  
    35  	// Test driver
    36  	if len(driver.VBoxManageCalls) != 2 {
    37  		t.Fatal("should call vboxmanage")
    38  	}
    39  	if driver.VBoxManageCalls[0][0] != "modifyvm" {
    40  		t.Fatal("bad")
    41  	}
    42  	if driver.VBoxManageCalls[1][0] != "export" {
    43  		t.Fatal("bad")
    44  	}
    45  }