github.com/sneal/packer@v0.5.2/builder/vmware/common/step_run_test.go (about)

     1  package common
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mitchellh/multistep"
     7  )
     8  
     9  func TestStepRun_impl(t *testing.T) {
    10  	var _ multistep.Step = new(StepRun)
    11  }
    12  
    13  func TestStepRun(t *testing.T) {
    14  	state := testState(t)
    15  	step := new(StepRun)
    16  
    17  	state.Put("vmx_path", "foo")
    18  
    19  	driver := state.Get("driver").(*DriverMock)
    20  
    21  	// Test the run
    22  	if action := step.Run(state); action != multistep.ActionContinue {
    23  		t.Fatalf("bad action: %#v", action)
    24  	}
    25  	if _, ok := state.GetOk("error"); ok {
    26  		t.Fatal("should NOT have error")
    27  	}
    28  
    29  	// Test the driver
    30  	if !driver.StartCalled {
    31  		t.Fatal("start should be called")
    32  	}
    33  	if driver.StartPath != "foo" {
    34  		t.Fatalf("bad: %#v", driver.StartPath)
    35  	}
    36  	if driver.StartHeadless {
    37  		t.Fatal("bad")
    38  	}
    39  
    40  	// Test cleanup
    41  	step.Cleanup(state)
    42  	if driver.StopCalled {
    43  		t.Fatal("stop should not be called if not running")
    44  	}
    45  }
    46  
    47  func TestStepRun_cleanupRunning(t *testing.T) {
    48  	state := testState(t)
    49  	step := new(StepRun)
    50  
    51  	state.Put("vmx_path", "foo")
    52  
    53  	driver := state.Get("driver").(*DriverMock)
    54  
    55  	// Test the run
    56  	if action := step.Run(state); action != multistep.ActionContinue {
    57  		t.Fatalf("bad action: %#v", action)
    58  	}
    59  	if _, ok := state.GetOk("error"); ok {
    60  		t.Fatal("should NOT have error")
    61  	}
    62  
    63  	// Test the driver
    64  	if !driver.StartCalled {
    65  		t.Fatal("start should be called")
    66  	}
    67  	if driver.StartPath != "foo" {
    68  		t.Fatalf("bad: %#v", driver.StartPath)
    69  	}
    70  	if driver.StartHeadless {
    71  		t.Fatal("bad")
    72  	}
    73  
    74  	// Mark that it is running
    75  	driver.IsRunningResult = true
    76  
    77  	// Test cleanup
    78  	step.Cleanup(state)
    79  	if !driver.StopCalled {
    80  		t.Fatal("stop should be called")
    81  	}
    82  }