github.com/mitchellh/packer@v1.3.2/builder/vmware/iso/step_register_test.go (about)

     1  package iso
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/packer/helper/multistep"
     8  )
     9  
    10  func TestStepRegister_impl(t *testing.T) {
    11  	var _ multistep.Step = new(StepRegister)
    12  }
    13  
    14  func TestStepRegister_regularDriver(t *testing.T) {
    15  	state := testState(t)
    16  	step := new(StepRegister)
    17  
    18  	state.Put("vmx_path", "foo")
    19  
    20  	// Test the run
    21  	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
    22  		t.Fatalf("bad action: %#v", action)
    23  	}
    24  	if _, ok := state.GetOk("error"); ok {
    25  		t.Fatal("should NOT have error")
    26  	}
    27  
    28  	// Cleanup
    29  	step.Cleanup(state)
    30  }
    31  
    32  func TestStepRegister_remoteDriver(t *testing.T) {
    33  	state := testState(t)
    34  	step := new(StepRegister)
    35  
    36  	driver := new(RemoteDriverMock)
    37  	var config Config
    38  	config.KeepRegistered = false
    39  	state.Put("config", &config)
    40  
    41  	state.Put("driver", driver)
    42  	state.Put("vmx_path", "foo")
    43  
    44  	// Test the run
    45  	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
    46  		t.Fatalf("bad action: %#v", action)
    47  	}
    48  	if _, ok := state.GetOk("error"); ok {
    49  		t.Fatal("should NOT have error")
    50  	}
    51  
    52  	// verify
    53  	if !driver.RegisterCalled {
    54  		t.Fatal("register should be called")
    55  	}
    56  	if driver.RegisterPath != "foo" {
    57  		t.Fatal("should call with correct path")
    58  	}
    59  	if driver.UnregisterCalled {
    60  		t.Fatal("unregister should not be called")
    61  	}
    62  
    63  	// cleanup
    64  	step.Cleanup(state)
    65  	if !driver.UnregisterCalled {
    66  		t.Fatal("unregister should be called")
    67  	}
    68  	if driver.UnregisterPath != "foo" {
    69  		t.Fatal("should unregister proper path")
    70  	}
    71  }
    72  func TestStepRegister_WithoutUnregister_remoteDriver(t *testing.T) {
    73  	state := testState(t)
    74  	step := new(StepRegister)
    75  
    76  	driver := new(RemoteDriverMock)
    77  	var config Config
    78  	config.KeepRegistered = true
    79  	state.Put("config", &config)
    80  
    81  	state.Put("driver", driver)
    82  	state.Put("vmx_path", "foo")
    83  
    84  	// Test the run
    85  	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
    86  		t.Fatalf("bad action: %#v", action)
    87  	}
    88  	if _, ok := state.GetOk("error"); ok {
    89  		t.Fatal("should NOT have error")
    90  	}
    91  
    92  	// cleanup
    93  	step.Cleanup(state)
    94  	if driver.UnregisterCalled {
    95  		t.Fatal("unregister should not be called")
    96  	}
    97  }