github.com/rothwerx/packer@v0.9.0/builder/parallels/common/step_compact_disk_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 TestStepCompactDisk_impl(t *testing.T) {
    12  	var _ multistep.Step = new(StepCompactDisk)
    13  }
    14  
    15  func TestStepCompactDisk(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 := new(StepCompactDisk)
    25  
    26  	state.Put("vmName", "foo")
    27  
    28  	driver := state.Get("driver").(*DriverMock)
    29  
    30  	// Mock results
    31  	driver.DiskPathResult = tf.Name()
    32  
    33  	// Test the run
    34  	if action := step.Run(state); action != multistep.ActionContinue {
    35  		t.Fatalf("bad action: %#v", action)
    36  	}
    37  	if _, ok := state.GetOk("error"); ok {
    38  		t.Fatal("should NOT have error")
    39  	}
    40  
    41  	// Test the driver
    42  	if !driver.CompactDiskCalled {
    43  		t.Fatal("should've called")
    44  	}
    45  
    46  	path, _ := driver.DiskPath("foo")
    47  	if path != tf.Name() {
    48  		t.Fatal("should call with right path")
    49  	}
    50  }
    51  
    52  func TestStepCompactDisk_skip(t *testing.T) {
    53  	state := testState(t)
    54  	step := new(StepCompactDisk)
    55  	step.Skip = true
    56  
    57  	state.Put("vmName", "foo")
    58  
    59  	driver := state.Get("driver").(*DriverMock)
    60  
    61  	// Test the run
    62  	if action := step.Run(state); action != multistep.ActionContinue {
    63  		t.Fatalf("bad action: %#v", action)
    64  	}
    65  	if _, ok := state.GetOk("error"); ok {
    66  		t.Fatal("should NOT have error")
    67  	}
    68  
    69  	// Test the driver
    70  	if driver.CompactDiskCalled {
    71  		t.Fatal("should not have called")
    72  	}
    73  }