From 23c6951aa411a8a965a99d7c4e462e8e51e460fd Mon Sep 17 00:00:00 2001 From: Andrey Tonkikh Date: Thu, 26 Oct 2017 01:04:44 +0300 Subject: [PATCH] Add an acceptance test for `driver.Folder` --- builder_acc_test.go | 8 +------- driver/testing/folder_acc_test.go | 14 ++++++++++++++ driver/testing/utility.go | 16 ++++++++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 driver/testing/folder_acc_test.go diff --git a/builder_acc_test.go b/builder_acc_test.go index 0d7e77f6c..a18e8d5f0 100644 --- a/builder_acc_test.go +++ b/builder_acc_test.go @@ -91,13 +91,7 @@ func checkFolder(t *testing.T, folder string) builderT.TestCheckFunc { } f := d.NewFolder(vmInfo.Parent) - path, err := f.Path() - if err != nil { - t.Fatalf("Cannot read folder name: %v", err) - } - if path != folder { - t.Errorf("Wrong folder. expected: %v, got: %v", folder, path) - } + driverT.CheckFolderPath(t, f, folder) return nil } diff --git a/driver/testing/folder_acc_test.go b/driver/testing/folder_acc_test.go new file mode 100644 index 000000000..fc436d0a1 --- /dev/null +++ b/driver/testing/folder_acc_test.go @@ -0,0 +1,14 @@ +package testing + +import "testing" + +func TestFolderAcc(t *testing.T) { + initDriverAcceptanceTest(t) + + d := NewTestDriver(t) + f, err := d.FindFolder(TestFolder) + if err != nil { + t.Fatalf("Cannot find the default folder '%v': %v", TestFolder, err) + } + CheckFolderPath(t, f, TestFolder) +} diff --git a/driver/testing/utility.go b/driver/testing/utility.go index 97ea812e6..a9d40e9a3 100644 --- a/driver/testing/utility.go +++ b/driver/testing/utility.go @@ -7,7 +7,6 @@ import ( "os" "testing" "time" - "github.com/vmware/govmomi/govc/pool" ) func NewTestDriver(t *testing.T) *driver.Driver { @@ -28,12 +27,12 @@ func NewVMName() string { return fmt.Sprintf("test-%v", rand.Intn(1000)) } -func CheckDatastoreName(t *testing.T, ds *driver.Datastore, name string) { +func CheckDatastoreName(t *testing.T, ds *driver.Datastore, datastore string) { switch info, err := ds.Info("name"); { case err != nil: t.Errorf("Cannot read datastore properties: %v", err) - case info.Name != name: - t.Errorf("Wrong datastore. expected: %v, got: %v", name, info.Name) + case info.Name != datastore: + t.Errorf("Wrong datastore. expected: %v, got: %v", datastore, info.Name) } } @@ -46,6 +45,15 @@ func CheckResourcePoolPath(t *testing.T, p *driver.ResourcePool, pool string) { } } +func CheckFolderPath(t *testing.T, f *driver.Folder, folder string) { + switch path, err := f.Path(); { + case err != nil: + t.Fatalf("Cannot read folder name: %v", err) + case path != folder: + t.Errorf("Wrong folder. expected: %v, got: %v", folder, path) + } +} + func initDriverAcceptanceTest(t *testing.T) { // We only run acceptance tests if an env var is set because they're // slow and require outside configuration.