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

     1  package common
     2  
     3  import (
     4  	"github.com/mitchellh/multistep"
     5  	"github.com/mitchellh/packer/packer"
     6  	"testing"
     7  )
     8  
     9  func TestStepUploadVersion_impl(t *testing.T) {
    10  	var _ multistep.Step = new(StepUploadVersion)
    11  }
    12  
    13  func TestStepUploadVersion(t *testing.T) {
    14  	state := testState(t)
    15  	step := new(StepUploadVersion)
    16  	step.Path = "foopath"
    17  
    18  	comm := new(packer.MockCommunicator)
    19  	state.Put("communicator", comm)
    20  
    21  	driver := state.Get("driver").(*DriverMock)
    22  	driver.VersionResult = "foo"
    23  
    24  	// Test the run
    25  	if action := step.Run(state); action != multistep.ActionContinue {
    26  		t.Fatalf("bad action: %#v", action)
    27  	}
    28  	if _, ok := state.GetOk("error"); ok {
    29  		t.Fatal("should NOT have error")
    30  	}
    31  
    32  	// Verify
    33  	if comm.UploadPath != "foopath" {
    34  		t.Fatalf("bad: %#v", comm.UploadPath)
    35  	}
    36  	if comm.UploadData != "foo" {
    37  		t.Fatalf("upload data bad: %#v", comm.UploadData)
    38  	}
    39  }
    40  
    41  func TestStepUploadVersion_noPath(t *testing.T) {
    42  	state := testState(t)
    43  	step := new(StepUploadVersion)
    44  	step.Path = ""
    45  
    46  	comm := new(packer.MockCommunicator)
    47  	state.Put("communicator", comm)
    48  
    49  	// Test the run
    50  	if action := step.Run(state); action != multistep.ActionContinue {
    51  		t.Fatalf("bad action: %#v", action)
    52  	}
    53  	if _, ok := state.GetOk("error"); ok {
    54  		t.Fatal("should NOT have error")
    55  	}
    56  
    57  	// Verify
    58  	if comm.UploadCalled {
    59  		t.Fatal("bad")
    60  	}
    61  }