From 7794c149a13c6aa1691b77056cc41ff98eb10108 Mon Sep 17 00:00:00 2001 From: Andrey Tonkikh Date: Wed, 8 Nov 2017 19:47:29 +0300 Subject: [PATCH] Inline test config --- builder_acc_test.go | 32 ++++++++++++------------ driver/testing/config.go | 22 ---------------- driver/testing/datastore_acc_test.go | 6 ++--- driver/testing/folder_acc_test.go | 6 ++--- driver/testing/host_acc_test.go | 9 ++++--- driver/testing/resource_pool_acc_test.go | 6 ++--- driver/testing/utility.go | 3 ++- driver/testing/vm_acc_test.go | 22 ++++++++-------- 8 files changed, 44 insertions(+), 62 deletions(-) delete mode 100644 driver/testing/config.go diff --git a/builder_acc_test.go b/builder_acc_test.go index a18e8d5f0..f18caaab0 100644 --- a/builder_acc_test.go +++ b/builder_acc_test.go @@ -17,7 +17,7 @@ func TestBuilderAcc_default(t *testing.T) { Check: func(artifacts []packer.Artifact) error { d := driverT.NewTestDriver(t) driverT.VMCheckDefault(t, d, getVM(t, d, artifacts), config["vm_name"].(string), - config["host"].(string), driverT.TestDatastore) + config["host"].(string), "datastore1") return nil }, }) @@ -25,13 +25,13 @@ func TestBuilderAcc_default(t *testing.T) { func defaultConfig() map[string]interface{} { config := map[string]interface{}{ - "vcenter_server": driverT.TestVCenterServer, - "username": driverT.TestVCenterUsername, - "password": driverT.TestVCenterPassword, + "vcenter_server": "vcenter.vsphere55.test", + "username": "root", + "password": "jetbrains", "insecure_connection": true, - "template": driverT.TestTemplate, - "host": driverT.TestHost, + "template": "alpine", + "host": "esxi-1.vsphere55.test", "ssh_username": "root", "ssh_password": "jetbrains", @@ -69,13 +69,13 @@ func TestBuilderAcc_folder(t *testing.T) { builderT.Test(t, builderT.TestCase{ Builder: &Builder{}, Template: folderConfig(), - Check: checkFolder(t, driverT.TestFolder), + Check: checkFolder(t, "folder1/folder2"), }) } func folderConfig() string { config := defaultConfig() - config["folder"] = driverT.TestFolder + config["folder"] = "folder1/folder2" config["linked_clone"] = true // speed up return renderConfig(config) } @@ -101,13 +101,13 @@ func TestBuilderAcc_resourcePool(t *testing.T) { builderT.Test(t, builderT.TestCase{ Builder: &Builder{}, Template: resourcePoolConfig(), - Check: checkResourcePool(t, driverT.TestResourcePool), + Check: checkResourcePool(t, "pool1/pool2"), }) } func resourcePoolConfig() string { config := defaultConfig() - config["resource_pool"] = driverT.TestResourcePool + config["resource_pool"] = "pool1/pool2" config["linked_clone"] = true // speed up return renderConfig(config) } @@ -133,7 +133,7 @@ func TestBuilderAcc_datastore(t *testing.T) { Template: datastoreConfig(), Check: func(artifacts []packer.Artifact) error { d := driverT.NewTestDriver(t) - driverT.VMCheckDatastore(t, d, getVM(t, d, artifacts), driverT.TestDatastore) + driverT.VMCheckDatastore(t, d, getVM(t, d, artifacts), "datastore1") return nil }, }) @@ -206,11 +206,11 @@ func TestBuilderAcc_hardware(t *testing.T) { func hardwareConfig() string { config := defaultConfig() - config["CPUs"] = driverT.TestCPUs - config["CPU_reservation"] = driverT.TestCPUReservation - config["CPU_limit"] = driverT.TestCPULimit - config["RAM"] = driverT.TestRAM - config["RAM_reservation"] = driverT.TestRAMReservation + config["CPUs"] = 2 + config["CPU_reservation"] = 1000 + config["CPU_limit"] = 1500 + config["RAM"] = 2048 + config["RAM_reservation"] = 1024 config["linked_clone"] = true // speed up return renderConfig(config) diff --git a/driver/testing/config.go b/driver/testing/config.go deleted file mode 100644 index 9e085dd6c..000000000 --- a/driver/testing/config.go +++ /dev/null @@ -1,22 +0,0 @@ -package testing - -// Defines whether acceptance tests should be run -const TestEnvVar = "VSPHERE_DRIVER_ACC" - -// Describe the environment to run tests in -const TestDatastore = "datastore1" -const TestTemplate = "alpine" -const TestHost = "esxi-1.vsphere55.test" -const TestVCenterServer = "vcenter.vsphere55.test" -const TestVCenterUsername = "root" -const TestVCenterPassword = "jetbrains" - -// For test of hardware settings -const TestCPUs = 2 -const TestCPUReservation = 1000 -const TestCPULimit = 1500 -const TestRAM = 2048 -const TestRAMReservation = 1024 - -const TestFolder = "folder1/folder2" -const TestResourcePool = "pool1/pool2" diff --git a/driver/testing/datastore_acc_test.go b/driver/testing/datastore_acc_test.go index 17eecf1ee..4643c0a5c 100644 --- a/driver/testing/datastore_acc_test.go +++ b/driver/testing/datastore_acc_test.go @@ -8,9 +8,9 @@ func TestDatastoreAcc(t *testing.T) { initDriverAcceptanceTest(t) d := NewTestDriver(t) - ds, err := d.FindDatastore(TestDatastore) + ds, err := d.FindDatastore("datastore1") if err != nil { - t.Fatalf("Cannot find the default datastore '%v': %v", TestDatastore, err) + t.Fatalf("Cannot find the default datastore '%v': %v", "datastore1", err) } - CheckDatastoreName(t, ds, TestDatastore) + CheckDatastoreName(t, ds, "datastore1") } diff --git a/driver/testing/folder_acc_test.go b/driver/testing/folder_acc_test.go index fc436d0a1..8555521fa 100644 --- a/driver/testing/folder_acc_test.go +++ b/driver/testing/folder_acc_test.go @@ -6,9 +6,9 @@ func TestFolderAcc(t *testing.T) { initDriverAcceptanceTest(t) d := NewTestDriver(t) - f, err := d.FindFolder(TestFolder) + f, err := d.FindFolder("folder1/folder2") if err != nil { - t.Fatalf("Cannot find the default folder '%v': %v", TestFolder, err) + t.Fatalf("Cannot find the default folder '%v': %v", "folder1/folder2", err) } - CheckFolderPath(t, f, TestFolder) + CheckFolderPath(t, f, "folder1/folder2") } diff --git a/driver/testing/host_acc_test.go b/driver/testing/host_acc_test.go index 92b08cf69..a9c35af7e 100644 --- a/driver/testing/host_acc_test.go +++ b/driver/testing/host_acc_test.go @@ -6,16 +6,17 @@ import ( func TestHostAcc(t *testing.T) { initDriverAcceptanceTest(t) + hostName := "esxi-1.vsphere55.test" d := NewTestDriver(t) - host, err := d.FindHost(TestHost) + host, err := d.FindHost(hostName) if err != nil { - t.Fatalf("Cannot find the default host '%v': %v", TestDatastore, err) + t.Fatalf("Cannot find the default host '%v': %v", "datastore1", err) } switch info, err := host.Info("name"); { case err != nil: t.Errorf("Cannot read host properties: %v", err) - case info.Name != TestHost: - t.Errorf("Wrong host name: expected '%v', got: '%v'", TestHost, info.Name) + case info.Name != hostName: + t.Errorf("Wrong host name: expected '%v', got: '%v'", hostName, info.Name) } } diff --git a/driver/testing/resource_pool_acc_test.go b/driver/testing/resource_pool_acc_test.go index 7b6177f90..b242e0b08 100644 --- a/driver/testing/resource_pool_acc_test.go +++ b/driver/testing/resource_pool_acc_test.go @@ -6,9 +6,9 @@ func TestResourcePoolAcc(t *testing.T) { initDriverAcceptanceTest(t) d := NewTestDriver(t) - p, err := d.FindResourcePool(TestHost, TestResourcePool) + p, err := d.FindResourcePool("esxi-1.vsphere55.test", "pool1/pool2") if err != nil { - t.Fatalf("Cannot find the default resource pool '%v': %v", TestResourcePool, err) + t.Fatalf("Cannot find the default resource pool '%v': %v", "pool1/pool2", err) } - CheckResourcePoolPath(t, p, TestResourcePool) + CheckResourcePoolPath(t, p, "pool1/pool2") } diff --git a/driver/testing/utility.go b/driver/testing/utility.go index 96d210370..707fc4d18 100644 --- a/driver/testing/utility.go +++ b/driver/testing/utility.go @@ -152,7 +152,8 @@ func VMCheckHardware(t* testing.T, d *driver.Driver, vm *driver.VirtualMachine) } func VMCheckTemplate(t* testing.T, d *driver.Driver, vm *driver.VirtualMachine) { - switch vmInfo, err := vm.Info("config.template"); { + vmInfo, err := vm.Info("config.template") + switch { case err != nil: t.Errorf("Cannot read VM properties: %v", err) case !vmInfo.Config.Template: diff --git a/driver/testing/vm_acc_test.go b/driver/testing/vm_acc_test.go index 594430ff2..b360c0dfc 100644 --- a/driver/testing/vm_acc_test.go +++ b/driver/testing/vm_acc_test.go @@ -10,21 +10,23 @@ import ( func initVMAccTest(t *testing.T) (d *driver.Driver, vm *driver.VirtualMachine, vmName string, vmDestructor func()) { initDriverAcceptanceTest(t) + + templateName := "alpine" d = NewTestDriver(t) - template, err := d.FindVM(TestTemplate) // Don't destroy this VM! + template, err := d.FindVM(templateName) // Don't destroy this VM! if err != nil { - t.Fatalf("Cannot find template vm '%v': %v", TestTemplate, err) + t.Fatalf("Cannot find template vm '%v': %v", templateName, err) } log.Printf("[DEBUG] Clonning VM") vmName = NewVMName() vm, err = template.Clone(&driver.CloneConfig{ Name: vmName, - Host: TestHost, + Host: "esxi-1.vsphere55.test", }) if err != nil { - t.Fatalf("Cannot clone vm '%v': %v", TestTemplate, err) + t.Fatalf("Cannot clone vm '%v': %v", templateName, err) } vmDestructor = func() { @@ -53,7 +55,7 @@ func TestVMAcc_default(t *testing.T) { // Run checks log.Printf("[DEBUG] Running check function") - VMCheckDefault(t, d, vm, vmName, TestHost, TestDatastore) + VMCheckDefault(t, d, vm, vmName, "esxi-1.vsphere55.test", "datastore1") } func TestVMAcc_hardware(t *testing.T) { @@ -62,11 +64,11 @@ func TestVMAcc_hardware(t *testing.T) { log.Printf("[DEBUG] Configuring the vm") vm.Configure(&driver.HardwareConfig{ - CPUs: TestCPUs, - CPUReservation: TestCPUReservation, - CPULimit: TestCPULimit, - RAM: TestRAM, - RAMReservation: TestRAMReservation, + CPUs: 2, + CPUReservation: 1000, + CPULimit: 1500, + RAM: 2048, + RAMReservation: 1024, }) log.Printf("[DEBUG] Running check function") VMCheckHardware(t, d, vm)