github.phpd.cn/hashicorp/packer@v1.3.2/builder/parallels/common/step_upload_parallels_tools_test.go (about)

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