test for folder

This commit is contained in:
Michael Kuzmin 2017-08-24 00:23:29 +03:00
parent 6c885f1994
commit 2c184abdef
2 changed files with 53 additions and 1 deletions

View File

@ -104,6 +104,44 @@ func checkArtifact(t *testing.T) builderT.TestCheckFunc {
}
}
func TestBuilderAcc_folder(t *testing.T) {
builderT.Test(t, builderT.TestCase{
Builder: &Builder{},
Template: folderConfig(),
Check: checkFolder(t, "folder1"),
})
}
func folderConfig() string {
config := defaultConfig()
config["folder"] = "folder1"
config["linked_clone"] = true // speed up
return renderConfig(config)
}
func checkFolder(t *testing.T, folder string) builderT.TestCheckFunc {
return func(artifacts []packer.Artifact) error {
d := testConn(t)
vm := getVM(t, d, artifacts)
vmInfo, err := d.VMInfo(vm, "parent")
if err != nil {
t.Fatalf("Cannot read VM properties: %v", err)
}
f := d.NewFolder(vmInfo.Parent)
path, err := d.GetFolderPath(f)
if err != nil {
t.Fatalf("Cannot read folder name: %v", err)
}
if path != folder {
t.Errorf("Wrong folder. expected: %v, got: %v", folder, path)
}
return nil
}
}
func TestBuilderAcc_linkedClone(t *testing.T) {
builderT.Test(t, builderT.TestCase{
Builder: &Builder{},
@ -179,8 +217,8 @@ func TestBuilderAcc_template(t *testing.T) {
func templateConfig() string {
config := defaultConfig()
config["linked_clone"] = true
config["convert_to_template"] = true
config["linked_clone"] = true // speed up
return renderConfig(config)
}

14
driver/folder.go Normal file
View File

@ -0,0 +1,14 @@
package driver
import (
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/vim25/types"
)
func (d *Driver) NewFolder(ref *types.ManagedObjectReference) *object.Folder {
return object.NewFolder(d.client.Client, *ref)
}
func (d *Driver) GetFolderPath(folder *object.Folder) (string, error) {
return folder.ObjectName(d.ctx)
}