adding new functional test

This commit is contained in:
Chris Love 2015-11-08 18:49:49 -07:00
parent 6e19c3f0e0
commit 106b126448
1 changed files with 82 additions and 1 deletions

View File

@ -127,6 +127,67 @@ func TestAccVSphereVirtualMachine_dhcp(t *testing.T) {
})
}
func TestAccVSphereVirtualMachine_custom_configs(t *testing.T) {
var vm virtualMachine
var locationOpt string
var datastoreOpt string
if v := os.Getenv("VSPHERE_DATACENTER"); v != "" {
locationOpt += fmt.Sprintf(" datacenter = \"%s\"\n", v)
}
if v := os.Getenv("VSPHERE_CLUSTER"); v != "" {
locationOpt += fmt.Sprintf(" cluster = \"%s\"\n", v)
}
if v := os.Getenv("VSPHERE_RESOURCE_POOL"); v != "" {
locationOpt += fmt.Sprintf(" resource_pool = \"%s\"\n", v)
}
if v := os.Getenv("VSPHERE_DATASTORE"); v != "" {
datastoreOpt = fmt.Sprintf(" datastore = \"%s\"\n", v)
}
template := os.Getenv("VSPHERE_TEMPLATE")
label := os.Getenv("VSPHERE_NETWORK_LABEL_DHCP")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVSphereVirtualMachineDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(
testAccCheckVSphereVirtualMachineConfig_custom_configs,
locationOpt,
label,
datastoreOpt,
template,
),
Check: resource.ComposeTestCheckFunc(
testAccCheckVSphereVirtualMachineExists("vsphere_virtual_machine.bar", &vm),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.car", "name", "terraform-test"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.car", "vcpu", "2"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.car", "memory", "4096"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.car", "disk.#", "1"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.car", "disk.0.template", template),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.car", "network_interface.#", "1"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.car", "custom_configuration_parameters.foo", "bar"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.car", "custom_configuration_parameters.car", "ferrai"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.car", "custom_configuration_parameters.num", "42"),
resource.TestCheckResourceAttr(
"vsphere_virtual_machine.bar", "network_interface.0.label", label),
),
},
},
})
}
func testAccCheckVSphereVirtualMachineDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*govmomi.Client)
finder := find.NewFinder(client.Client, true)
@ -212,7 +273,6 @@ resource "vsphere_virtual_machine" "foo" {
}
}
`
const testAccCheckVSphereVirtualMachineConfig_dhcp = `
resource "vsphere_virtual_machine" "bar" {
name = "terraform-test"
@ -228,3 +288,24 @@ resource "vsphere_virtual_machine" "bar" {
}
}
`
const testAccCheckVSphereVirtualMachineConfig_custom_configs = `
resource "vsphere_virtual_machine" "car" {
name = "terraform-test-custom"
%s
vcpu = 2
memory = 4096
network_interface {
label = "%s"
}
custom_configuration_parameters {
foo = "bar",
car = "ferrai",
num = 42
}
disk {
%s
template = "%s"
}
}
`