packer-cn/builder/vmware/vmx/step_clone_vmx_test.go

75 lines
1.7 KiB
Go
Raw Normal View History

2013-12-26 10:34:27 -05:00
package vmx
import (
"io/ioutil"
"os"
"path/filepath"
2013-12-26 10:34:27 -05:00
"testing"
2017-04-04 16:39:01 -04:00
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
2013-12-26 10:34:27 -05:00
"github.com/mitchellh/multistep"
)
func TestStepCloneVMX_impl(t *testing.T) {
var _ multistep.Step = new(StepCloneVMX)
}
func TestStepCloneVMX(t *testing.T) {
// Setup some state
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.RemoveAll(td)
// Create the source
sourcePath := filepath.Join(td, "source.vmx")
if err := ioutil.WriteFile(sourcePath, []byte(testCloneVMX), 0644); err != nil {
t.Fatalf("err: %s", err)
}
// Create the dest because the mock driver won't
destPath := filepath.Join(td, "foo.vmx")
if err := ioutil.WriteFile(destPath, []byte(testCloneVMX), 0644); err != nil {
t.Fatalf("err: %s", err)
}
2013-12-26 10:34:27 -05:00
state := testState(t)
step := new(StepCloneVMX)
step.OutputDir = td
step.Path = sourcePath
2013-12-26 10:34:27 -05:00
step.VMName = "foo"
2013-12-26 16:39:41 -05:00
driver := state.Get("driver").(*vmwcommon.DriverMock)
2013-12-26 10:34:27 -05:00
// Test the run
if action := step.Run(state); action != multistep.ActionContinue {
t.Fatalf("bad action: %#v", action)
}
if _, ok := state.GetOk("error"); ok {
t.Fatal("should NOT have error")
}
// Test we cloned
2013-12-26 16:39:41 -05:00
if !driver.CloneCalled {
t.Fatal("should call clone")
}
// Test that we have our paths
if vmxPath, ok := state.GetOk("vmx_path"); !ok {
t.Fatal("should set vmx_path")
} else if vmxPath != destPath {
t.Fatalf("bad: %#v", vmxPath)
}
if diskPath, ok := state.GetOk("full_disk_path"); !ok {
t.Fatal("should set full_disk_path")
} else if diskPath != filepath.Join(td, "foo") {
t.Fatalf("bad: %#v", diskPath)
2013-12-26 10:34:27 -05:00
}
}
const testCloneVMX = `
scsi0:0.fileName = "foo"
`