github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/builder/parallels/common/step_upload_parallels_tools_test.go (about)

     1  package common
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mitchellh/multistep"
     7  	"github.com/mitchellh/packer/packer"
     8  )
     9  
    10  func TestStepUploadParallelsTools_impl(t *testing.T) {
    11  	var _ multistep.Step = new(StepUploadParallelsTools)
    12  }
    13  
    14  func TestStepUploadParallelsTools(t *testing.T) {
    15  	state := testState(t)
    16  	state.Put("parallels_tools_path", "./step_upload_parallels_tools_test.go")
    17  	step := new(StepUploadParallelsTools)
    18  	step.ParallelsToolsMode = "upload"
    19  	step.ParallelsToolsGuestPath = "/tmp/prl-lin.iso"
    20  	step.ParallelsToolsFlavor = "lin"
    21  
    22  	comm := new(packer.MockCommunicator)
    23  	state.Put("communicator", comm)
    24  
    25  	// Test the run
    26  	if action := step.Run(state); action != multistep.ActionContinue {
    27  		t.Fatalf("bad action: %#v", action)
    28  	}
    29  	if _, ok := state.GetOk("error"); ok {
    30  		t.Fatal("should NOT have error")
    31  	}
    32  
    33  	// Verify
    34  	if comm.UploadPath != "/tmp/prl-lin.iso" {
    35  		t.Fatalf("bad: %#v", comm.UploadPath)
    36  	}
    37  }
    38  
    39  func TestStepUploadParallelsTools_interpolate(t *testing.T) {
    40  	state := testState(t)
    41  	state.Put("parallels_tools_path", "./step_upload_parallels_tools_test.go")
    42  	step := new(StepUploadParallelsTools)
    43  	step.ParallelsToolsMode = "upload"
    44  	step.ParallelsToolsGuestPath = "/tmp/prl-{{ .Flavor }}.iso"
    45  	step.ParallelsToolsFlavor = "win"
    46  
    47  	comm := new(packer.MockCommunicator)
    48  	state.Put("communicator", comm)
    49  
    50  	// Test the run
    51  	if action := step.Run(state); action != multistep.ActionContinue {
    52  		t.Fatalf("bad action: %#v", action)
    53  	}
    54  	if _, ok := state.GetOk("error"); ok {
    55  		t.Fatal("should NOT have error")
    56  	}
    57  
    58  	// Verify
    59  	if comm.UploadPath != "/tmp/prl-win.iso" {
    60  		t.Fatalf("bad: %#v", comm.UploadPath)
    61  	}
    62  }
    63  
    64  func TestStepUploadParallelsTools_attach(t *testing.T) {
    65  	state := testState(t)
    66  	state.Put("parallels_tools_path", "./step_upload_parallels_tools_test.go")
    67  	step := new(StepUploadParallelsTools)
    68  	step.ParallelsToolsMode = "attach"
    69  	step.ParallelsToolsGuestPath = "/tmp/prl-lin.iso"
    70  	step.ParallelsToolsFlavor = "lin"
    71  
    72  	comm := new(packer.MockCommunicator)
    73  	state.Put("communicator", comm)
    74  
    75  	// Test the run
    76  	if action := step.Run(state); action != multistep.ActionContinue {
    77  		t.Fatalf("bad action: %#v", action)
    78  	}
    79  	if _, ok := state.GetOk("error"); ok {
    80  		t.Fatal("should NOT have error")
    81  	}
    82  
    83  	// Verify
    84  	if comm.UploadCalled {
    85  		t.Fatal("bad")
    86  	}
    87  }