Inline test config
This commit is contained in:
parent
c41ee01537
commit
7794c149a1
|
@ -17,7 +17,7 @@ func TestBuilderAcc_default(t *testing.T) {
|
||||||
Check: func(artifacts []packer.Artifact) error {
|
Check: func(artifacts []packer.Artifact) error {
|
||||||
d := driverT.NewTestDriver(t)
|
d := driverT.NewTestDriver(t)
|
||||||
driverT.VMCheckDefault(t, d, getVM(t, d, artifacts), config["vm_name"].(string),
|
driverT.VMCheckDefault(t, d, getVM(t, d, artifacts), config["vm_name"].(string),
|
||||||
config["host"].(string), driverT.TestDatastore)
|
config["host"].(string), "datastore1")
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -25,13 +25,13 @@ func TestBuilderAcc_default(t *testing.T) {
|
||||||
|
|
||||||
func defaultConfig() map[string]interface{} {
|
func defaultConfig() map[string]interface{} {
|
||||||
config := map[string]interface{}{
|
config := map[string]interface{}{
|
||||||
"vcenter_server": driverT.TestVCenterServer,
|
"vcenter_server": "vcenter.vsphere55.test",
|
||||||
"username": driverT.TestVCenterUsername,
|
"username": "root",
|
||||||
"password": driverT.TestVCenterPassword,
|
"password": "jetbrains",
|
||||||
"insecure_connection": true,
|
"insecure_connection": true,
|
||||||
|
|
||||||
"template": driverT.TestTemplate,
|
"template": "alpine",
|
||||||
"host": driverT.TestHost,
|
"host": "esxi-1.vsphere55.test",
|
||||||
|
|
||||||
"ssh_username": "root",
|
"ssh_username": "root",
|
||||||
"ssh_password": "jetbrains",
|
"ssh_password": "jetbrains",
|
||||||
|
@ -69,13 +69,13 @@ func TestBuilderAcc_folder(t *testing.T) {
|
||||||
builderT.Test(t, builderT.TestCase{
|
builderT.Test(t, builderT.TestCase{
|
||||||
Builder: &Builder{},
|
Builder: &Builder{},
|
||||||
Template: folderConfig(),
|
Template: folderConfig(),
|
||||||
Check: checkFolder(t, driverT.TestFolder),
|
Check: checkFolder(t, "folder1/folder2"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func folderConfig() string {
|
func folderConfig() string {
|
||||||
config := defaultConfig()
|
config := defaultConfig()
|
||||||
config["folder"] = driverT.TestFolder
|
config["folder"] = "folder1/folder2"
|
||||||
config["linked_clone"] = true // speed up
|
config["linked_clone"] = true // speed up
|
||||||
return renderConfig(config)
|
return renderConfig(config)
|
||||||
}
|
}
|
||||||
|
@ -101,13 +101,13 @@ func TestBuilderAcc_resourcePool(t *testing.T) {
|
||||||
builderT.Test(t, builderT.TestCase{
|
builderT.Test(t, builderT.TestCase{
|
||||||
Builder: &Builder{},
|
Builder: &Builder{},
|
||||||
Template: resourcePoolConfig(),
|
Template: resourcePoolConfig(),
|
||||||
Check: checkResourcePool(t, driverT.TestResourcePool),
|
Check: checkResourcePool(t, "pool1/pool2"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourcePoolConfig() string {
|
func resourcePoolConfig() string {
|
||||||
config := defaultConfig()
|
config := defaultConfig()
|
||||||
config["resource_pool"] = driverT.TestResourcePool
|
config["resource_pool"] = "pool1/pool2"
|
||||||
config["linked_clone"] = true // speed up
|
config["linked_clone"] = true // speed up
|
||||||
return renderConfig(config)
|
return renderConfig(config)
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ func TestBuilderAcc_datastore(t *testing.T) {
|
||||||
Template: datastoreConfig(),
|
Template: datastoreConfig(),
|
||||||
Check: func(artifacts []packer.Artifact) error {
|
Check: func(artifacts []packer.Artifact) error {
|
||||||
d := driverT.NewTestDriver(t)
|
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
|
return nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -206,11 +206,11 @@ func TestBuilderAcc_hardware(t *testing.T) {
|
||||||
|
|
||||||
func hardwareConfig() string {
|
func hardwareConfig() string {
|
||||||
config := defaultConfig()
|
config := defaultConfig()
|
||||||
config["CPUs"] = driverT.TestCPUs
|
config["CPUs"] = 2
|
||||||
config["CPU_reservation"] = driverT.TestCPUReservation
|
config["CPU_reservation"] = 1000
|
||||||
config["CPU_limit"] = driverT.TestCPULimit
|
config["CPU_limit"] = 1500
|
||||||
config["RAM"] = driverT.TestRAM
|
config["RAM"] = 2048
|
||||||
config["RAM_reservation"] = driverT.TestRAMReservation
|
config["RAM_reservation"] = 1024
|
||||||
config["linked_clone"] = true // speed up
|
config["linked_clone"] = true // speed up
|
||||||
|
|
||||||
return renderConfig(config)
|
return renderConfig(config)
|
||||||
|
|
|
@ -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"
|
|
|
@ -8,9 +8,9 @@ func TestDatastoreAcc(t *testing.T) {
|
||||||
initDriverAcceptanceTest(t)
|
initDriverAcceptanceTest(t)
|
||||||
|
|
||||||
d := NewTestDriver(t)
|
d := NewTestDriver(t)
|
||||||
ds, err := d.FindDatastore(TestDatastore)
|
ds, err := d.FindDatastore("datastore1")
|
||||||
if err != nil {
|
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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ func TestFolderAcc(t *testing.T) {
|
||||||
initDriverAcceptanceTest(t)
|
initDriverAcceptanceTest(t)
|
||||||
|
|
||||||
d := NewTestDriver(t)
|
d := NewTestDriver(t)
|
||||||
f, err := d.FindFolder(TestFolder)
|
f, err := d.FindFolder("folder1/folder2")
|
||||||
if err != nil {
|
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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,16 +6,17 @@ import (
|
||||||
|
|
||||||
func TestHostAcc(t *testing.T) {
|
func TestHostAcc(t *testing.T) {
|
||||||
initDriverAcceptanceTest(t)
|
initDriverAcceptanceTest(t)
|
||||||
|
hostName := "esxi-1.vsphere55.test"
|
||||||
|
|
||||||
d := NewTestDriver(t)
|
d := NewTestDriver(t)
|
||||||
host, err := d.FindHost(TestHost)
|
host, err := d.FindHost(hostName)
|
||||||
if err != nil {
|
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"); {
|
switch info, err := host.Info("name"); {
|
||||||
case err != nil:
|
case err != nil:
|
||||||
t.Errorf("Cannot read host properties: %v", err)
|
t.Errorf("Cannot read host properties: %v", err)
|
||||||
case info.Name != TestHost:
|
case info.Name != hostName:
|
||||||
t.Errorf("Wrong host name: expected '%v', got: '%v'", TestHost, info.Name)
|
t.Errorf("Wrong host name: expected '%v', got: '%v'", hostName, info.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ func TestResourcePoolAcc(t *testing.T) {
|
||||||
initDriverAcceptanceTest(t)
|
initDriverAcceptanceTest(t)
|
||||||
|
|
||||||
d := NewTestDriver(t)
|
d := NewTestDriver(t)
|
||||||
p, err := d.FindResourcePool(TestHost, TestResourcePool)
|
p, err := d.FindResourcePool("esxi-1.vsphere55.test", "pool1/pool2")
|
||||||
if err != nil {
|
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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
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:
|
case err != nil:
|
||||||
t.Errorf("Cannot read VM properties: %v", err)
|
t.Errorf("Cannot read VM properties: %v", err)
|
||||||
case !vmInfo.Config.Template:
|
case !vmInfo.Config.Template:
|
||||||
|
|
|
@ -10,21 +10,23 @@ import (
|
||||||
|
|
||||||
func initVMAccTest(t *testing.T) (d *driver.Driver, vm *driver.VirtualMachine, vmName string, vmDestructor func()) {
|
func initVMAccTest(t *testing.T) (d *driver.Driver, vm *driver.VirtualMachine, vmName string, vmDestructor func()) {
|
||||||
initDriverAcceptanceTest(t)
|
initDriverAcceptanceTest(t)
|
||||||
|
|
||||||
|
templateName := "alpine"
|
||||||
d = NewTestDriver(t)
|
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 {
|
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")
|
log.Printf("[DEBUG] Clonning VM")
|
||||||
vmName = NewVMName()
|
vmName = NewVMName()
|
||||||
vm, err = template.Clone(&driver.CloneConfig{
|
vm, err = template.Clone(&driver.CloneConfig{
|
||||||
Name: vmName,
|
Name: vmName,
|
||||||
Host: TestHost,
|
Host: "esxi-1.vsphere55.test",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot clone vm '%v': %v", TestTemplate, err)
|
t.Fatalf("Cannot clone vm '%v': %v", templateName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
vmDestructor = func() {
|
vmDestructor = func() {
|
||||||
|
@ -53,7 +55,7 @@ func TestVMAcc_default(t *testing.T) {
|
||||||
|
|
||||||
// Run checks
|
// Run checks
|
||||||
log.Printf("[DEBUG] Running check function")
|
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) {
|
func TestVMAcc_hardware(t *testing.T) {
|
||||||
|
@ -62,11 +64,11 @@ func TestVMAcc_hardware(t *testing.T) {
|
||||||
|
|
||||||
log.Printf("[DEBUG] Configuring the vm")
|
log.Printf("[DEBUG] Configuring the vm")
|
||||||
vm.Configure(&driver.HardwareConfig{
|
vm.Configure(&driver.HardwareConfig{
|
||||||
CPUs: TestCPUs,
|
CPUs: 2,
|
||||||
CPUReservation: TestCPUReservation,
|
CPUReservation: 1000,
|
||||||
CPULimit: TestCPULimit,
|
CPULimit: 1500,
|
||||||
RAM: TestRAM,
|
RAM: 2048,
|
||||||
RAMReservation: TestRAMReservation,
|
RAMReservation: 1024,
|
||||||
})
|
})
|
||||||
log.Printf("[DEBUG] Running check function")
|
log.Printf("[DEBUG] Running check function")
|
||||||
VMCheckHardware(t, d, vm)
|
VMCheckHardware(t, d, vm)
|
||||||
|
|
Loading…
Reference in New Issue