github.com/mitchellh/packer@v1.3.2/builder/vmware/common/step_compact_disk_test.go (about)

     1  package common
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/packer/helper/multistep"
     8  )
     9  
    10  func TestStepCompactDisk_impl(t *testing.T) {
    11  	var _ multistep.Step = new(StepCompactDisk)
    12  }
    13  
    14  func TestStepCompactDisk(t *testing.T) {
    15  	state := testState(t)
    16  	step := new(StepCompactDisk)
    17  
    18  	diskFullPaths := []string{"foo"}
    19  	state.Put("disk_full_paths", diskFullPaths)
    20  
    21  	driver := state.Get("driver").(*DriverMock)
    22  
    23  	// Test the run
    24  	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
    25  		t.Fatalf("bad action: %#v", action)
    26  	}
    27  	if _, ok := state.GetOk("error"); ok {
    28  		t.Fatal("should NOT have error")
    29  	}
    30  
    31  	// Test the driver
    32  	if !driver.CompactDiskCalled {
    33  		t.Fatal("should've called")
    34  	}
    35  	if driver.CompactDiskPath != "foo" {
    36  		t.Fatal("should call with right path")
    37  	}
    38  }
    39  
    40  func TestStepCompactDisk_skip(t *testing.T) {
    41  	state := testState(t)
    42  	step := new(StepCompactDisk)
    43  	step.Skip = true
    44  
    45  	diskFullPaths := []string{"foo"}
    46  	state.Put("disk_full_paths", diskFullPaths)
    47  
    48  	driver := state.Get("driver").(*DriverMock)
    49  
    50  	// Test the run
    51  	if action := step.Run(context.Background(), 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  	// Test the driver
    59  	if driver.CompactDiskCalled {
    60  		t.Fatal("should not have called")
    61  	}
    62  }