Inline test config

This commit is contained in:
Andrey Tonkikh 2017-11-08 19:47:29 +03:00 committed by Andrei Tonkikh
parent c41ee01537
commit 7794c149a1
8 changed files with 44 additions and 62 deletions

View File

@ -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)

View File

@ -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"

View File

@ -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")
}

View File

@ -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")
}

View File

@ -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)
}
}

View File

@ -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")
}

View File

@ -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:

View File

@ -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)