github.com/rothwerx/packer@v0.9.0/builder/vmware/vmx/step_clone_vmx_test.go (about) 1 package vmx 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "testing" 8 9 "github.com/mitchellh/multistep" 10 vmwcommon "github.com/mitchellh/packer/builder/vmware/common" 11 ) 12 13 func TestStepCloneVMX_impl(t *testing.T) { 14 var _ multistep.Step = new(StepCloneVMX) 15 } 16 17 func TestStepCloneVMX(t *testing.T) { 18 // Setup some state 19 td, err := ioutil.TempDir("", "packer") 20 if err != nil { 21 t.Fatalf("err: %s", err) 22 } 23 defer os.RemoveAll(td) 24 25 // Create the source 26 sourcePath := filepath.Join(td, "source.vmx") 27 if err := ioutil.WriteFile(sourcePath, []byte(testCloneVMX), 0644); err != nil { 28 t.Fatalf("err: %s", err) 29 } 30 31 // Create the dest because the mock driver won't 32 destPath := filepath.Join(td, "foo.vmx") 33 if err := ioutil.WriteFile(destPath, []byte(testCloneVMX), 0644); err != nil { 34 t.Fatalf("err: %s", err) 35 } 36 37 state := testState(t) 38 step := new(StepCloneVMX) 39 step.OutputDir = td 40 step.Path = sourcePath 41 step.VMName = "foo" 42 43 driver := state.Get("driver").(*vmwcommon.DriverMock) 44 45 // Test the run 46 if action := step.Run(state); action != multistep.ActionContinue { 47 t.Fatalf("bad action: %#v", action) 48 } 49 if _, ok := state.GetOk("error"); ok { 50 t.Fatal("should NOT have error") 51 } 52 53 // Test we cloned 54 if !driver.CloneCalled { 55 t.Fatal("should call clone") 56 } 57 58 // Test that we have our paths 59 if vmxPath, ok := state.GetOk("vmx_path"); !ok { 60 t.Fatal("should set vmx_path") 61 } else if vmxPath != destPath { 62 t.Fatalf("bad: %#v", vmxPath) 63 } 64 65 if diskPath, ok := state.GetOk("full_disk_path"); !ok { 66 t.Fatal("should set full_disk_path") 67 } else if diskPath != filepath.Join(td, "foo") { 68 t.Fatalf("bad: %#v", diskPath) 69 } 70 } 71 72 const testCloneVMX = ` 73 scsi0:0.fileName = "foo" 74 `