github.com/rothwerx/packer@v0.9.0/builder/vmware/common/step_prepare_tools_test.go (about)

     1  package common
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/mitchellh/multistep"
     9  )
    10  
    11  func TestStepPrepareTools_impl(t *testing.T) {
    12  	var _ multistep.Step = new(StepPrepareTools)
    13  }
    14  
    15  func TestStepPrepareTools(t *testing.T) {
    16  	tf, err := ioutil.TempFile("", "packer")
    17  	if err != nil {
    18  		t.Fatalf("err: %s", err)
    19  	}
    20  	tf.Close()
    21  	defer os.Remove(tf.Name())
    22  
    23  	state := testState(t)
    24  	step := &StepPrepareTools{
    25  		RemoteType:        "",
    26  		ToolsUploadFlavor: "foo",
    27  	}
    28  
    29  	driver := state.Get("driver").(*DriverMock)
    30  
    31  	// Mock results
    32  	driver.ToolsIsoPathResult = tf.Name()
    33  
    34  	// Test the run
    35  	if action := step.Run(state); action != multistep.ActionContinue {
    36  		t.Fatalf("bad action: %#v", action)
    37  	}
    38  	if _, ok := state.GetOk("error"); ok {
    39  		t.Fatal("should NOT have error")
    40  	}
    41  
    42  	// Test the driver
    43  	if !driver.ToolsIsoPathCalled {
    44  		t.Fatal("tools iso path should be called")
    45  	}
    46  	if driver.ToolsIsoPathFlavor != "foo" {
    47  		t.Fatalf("bad: %#v", driver.ToolsIsoPathFlavor)
    48  	}
    49  
    50  	// Test the resulting state
    51  	path, ok := state.GetOk("tools_upload_source")
    52  	if !ok {
    53  		t.Fatal("should have tools_upload_source")
    54  	}
    55  	if path != tf.Name() {
    56  		t.Fatalf("bad: %#v", path)
    57  	}
    58  }
    59  
    60  func TestStepPrepareTools_esx5(t *testing.T) {
    61  	state := testState(t)
    62  	step := &StepPrepareTools{
    63  		RemoteType:        "esx5",
    64  		ToolsUploadFlavor: "foo",
    65  	}
    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 the driver
    78  	if driver.ToolsIsoPathCalled {
    79  		t.Fatal("tools iso path should NOT be called")
    80  	}
    81  }
    82  
    83  func TestStepPrepareTools_nonExist(t *testing.T) {
    84  	state := testState(t)
    85  	step := &StepPrepareTools{
    86  		RemoteType:        "",
    87  		ToolsUploadFlavor: "foo",
    88  	}
    89  
    90  	driver := state.Get("driver").(*DriverMock)
    91  
    92  	// Mock results
    93  	driver.ToolsIsoPathResult = "foo"
    94  
    95  	// Test the run
    96  	if action := step.Run(state); action != multistep.ActionHalt {
    97  		t.Fatalf("bad action: %#v", action)
    98  	}
    99  	if _, ok := state.GetOk("error"); !ok {
   100  		t.Fatal("should have error")
   101  	}
   102  
   103  	// Test the driver
   104  	if !driver.ToolsIsoPathCalled {
   105  		t.Fatal("tools iso path should be called")
   106  	}
   107  	if driver.ToolsIsoPathFlavor != "foo" {
   108  		t.Fatalf("bad: %#v", driver.ToolsIsoPathFlavor)
   109  	}
   110  
   111  	// Test the resulting state
   112  	if _, ok := state.GetOk("tools_upload_source"); ok {
   113  		t.Fatal("should NOT have tools_upload_source")
   114  	}
   115  }