Fix tests and reconfigure for support of multi-disk vm

This commit is contained in:
DanHam 2018-03-30 22:00:21 +01:00
parent 6c9d4efd9f
commit 1aee759f06
No known key found for this signature in database
GPG Key ID: 58E79AEDD6AA987E
1 changed files with 32 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package vmx
import ( import (
"context" "context"
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -9,6 +10,14 @@ import (
vmwcommon "github.com/hashicorp/packer/builder/vmware/common" vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
"github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/helper/multistep"
"github.com/stretchr/testify/assert"
)
const (
scsiFilename = "scsiDisk.vmdk"
sataFilename = "sataDisk.vmdk"
nvmeFilename = "nvmeDisk.vmdk"
ideFilename = "ideDisk.vmdk"
) )
func TestStepCloneVMX_impl(t *testing.T) { func TestStepCloneVMX_impl(t *testing.T) {
@ -23,6 +32,21 @@ func TestStepCloneVMX(t *testing.T) {
} }
defer os.RemoveAll(td) defer os.RemoveAll(td)
// Set up mock vmx file contents
var testCloneVMX = fmt.Sprintf("scsi0:0.filename = \"%s\"\n"+
"sata0:0.filename = \"%s\"\n"+
"nvme0:0.filename = \"%s\"\n"+
"ide1:0.filename = \"%s\"\n"+
"ide0:0.filename = \"auto detect\"\n", scsiFilename,
sataFilename, nvmeFilename, ideFilename)
// Set up expected mock disk file paths
diskFilenames := []string{scsiFilename, sataFilename, ideFilename, nvmeFilename}
var diskPaths []string
for _, diskFilename := range diskFilenames {
diskPaths = append(diskPaths, filepath.Join(td, diskFilename))
}
// Create the source // Create the source
sourcePath := filepath.Join(td, "source.vmx") sourcePath := filepath.Join(td, "source.vmx")
if err := ioutil.WriteFile(sourcePath, []byte(testCloneVMX), 0644); err != nil { if err := ioutil.WriteFile(sourcePath, []byte(testCloneVMX), 0644); err != nil {
@ -65,11 +89,14 @@ func TestStepCloneVMX(t *testing.T) {
if diskPath, ok := state.GetOk("full_disk_path"); !ok { if diskPath, ok := state.GetOk("full_disk_path"); !ok {
t.Fatal("should set full_disk_path") t.Fatal("should set full_disk_path")
} else if diskPath != filepath.Join(td, "foo") { } else if diskPath != diskPaths[0] {
t.Fatalf("bad: %#v", diskPath) t.Fatalf("bad: %#v", diskPath)
} }
}
const testCloneVMX = ` if stateDiskPaths, ok := state.GetOk("additional_disk_paths"); !ok {
scsi0:0.fileName = "foo" t.Fatal("should set additional_disk_paths")
` } else {
assert.ElementsMatchf(t, stateDiskPaths.([]string), diskPaths[1:],
"%s\nshould contain the same elements as:\n%s", stateDiskPaths.([]string), diskPaths[1:])
}
}