From 3fbeb326cd53f75e01350df06eae89e681b54314 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Wed, 14 Oct 2015 21:34:07 -0500 Subject: [PATCH] provider/azure: acc tests fixes * avoid name collisions * update image names --- builtin/providers/azure/provider_test.go | 6 + .../azure/resource_azure_data_disk_test.go | 138 +++++++++--------- .../azure/resource_azure_instance_test.go | 4 +- 3 files changed, 81 insertions(+), 67 deletions(-) diff --git a/builtin/providers/azure/provider_test.go b/builtin/providers/azure/provider_test.go index b3feb8392..ca4017aae 100644 --- a/builtin/providers/azure/provider_test.go +++ b/builtin/providers/azure/provider_test.go @@ -3,9 +3,11 @@ package azure import ( "io" "io/ioutil" + "math/rand" "os" "strings" "testing" + "time" "github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/helper/schema" @@ -193,6 +195,10 @@ func TestAzure_isFile(t *testing.T) { } } +func genRandInt() int { + return rand.New(rand.NewSource(time.Now().UnixNano())).Int() % 100000 +} + // testAzurePublishSettingsStr is a revoked publishsettings file const testAzurePublishSettingsStr = ` diff --git a/builtin/providers/azure/resource_azure_data_disk_test.go b/builtin/providers/azure/resource_azure_data_disk_test.go index dfad26b5e..2c6660f66 100644 --- a/builtin/providers/azure/resource_azure_data_disk_test.go +++ b/builtin/providers/azure/resource_azure_data_disk_test.go @@ -13,6 +13,7 @@ import ( func TestAccAzureDataDisk_basic(t *testing.T) { var disk virtualmachinedisk.DataDiskResponse + name := fmt.Sprintf("terraform-test%d", genRandInt()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -20,13 +21,13 @@ func TestAccAzureDataDisk_basic(t *testing.T) { CheckDestroy: testAccCheckAzureDataDiskDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAzureDataDisk_basic, + Config: testAccAzureDataDisk_basic(name), Check: resource.ComposeTestCheckFunc( testAccCheckAzureDataDiskExists( "azure_data_disk.foo", &disk), testAccCheckAzureDataDiskAttributes(&disk), resource.TestCheckResourceAttr( - "azure_data_disk.foo", "label", "terraform-test-0"), + "azure_data_disk.foo", "label", fmt.Sprintf("%s-0", name)), resource.TestCheckResourceAttr( "azure_data_disk.foo", "size", "10"), ), @@ -37,6 +38,7 @@ func TestAccAzureDataDisk_basic(t *testing.T) { func TestAccAzureDataDisk_update(t *testing.T) { var disk virtualmachinedisk.DataDiskResponse + name := fmt.Sprintf("terraform-test%d", genRandInt()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -44,12 +46,12 @@ func TestAccAzureDataDisk_update(t *testing.T) { CheckDestroy: testAccCheckAzureDataDiskDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAzureDataDisk_advanced, + Config: testAccAzureDataDisk_advanced(name), Check: resource.ComposeTestCheckFunc( testAccCheckAzureDataDiskExists( "azure_data_disk.foo", &disk), resource.TestCheckResourceAttr( - "azure_data_disk.foo", "label", "terraform-test1-1"), + "azure_data_disk.foo", "label", fmt.Sprintf("%s-1", name)), resource.TestCheckResourceAttr( "azure_data_disk.foo", "lun", "1"), resource.TestCheckResourceAttr( @@ -57,17 +59,17 @@ func TestAccAzureDataDisk_update(t *testing.T) { resource.TestCheckResourceAttr( "azure_data_disk.foo", "caching", "ReadOnly"), resource.TestCheckResourceAttr( - "azure_data_disk.foo", "virtual_machine", "terraform-test1"), + "azure_data_disk.foo", "virtual_machine", name), ), }, resource.TestStep{ - Config: testAccAzureDataDisk_update, + Config: testAccAzureDataDisk_update(name), Check: resource.ComposeTestCheckFunc( testAccCheckAzureDataDiskExists( "azure_data_disk.foo", &disk), resource.TestCheckResourceAttr( - "azure_data_disk.foo", "label", "terraform-test1-1"), + "azure_data_disk.foo", "label", fmt.Sprintf("%s-1", name)), resource.TestCheckResourceAttr( "azure_data_disk.foo", "lun", "2"), resource.TestCheckResourceAttr( @@ -168,68 +170,74 @@ func testAccCheckAzureDataDiskDestroy(s *terraform.State) error { return nil } -var testAccAzureDataDisk_basic = fmt.Sprintf(` -resource "azure_instance" "foo" { - name = "terraform-test" - image = "Ubuntu Server 14.04 LTS" - size = "Basic_A1" - storage_service_name = "%s" - location = "West US" - username = "terraform" - password = "Pass!admin123" +func testAccAzureDataDisk_basic(name string) string { + return fmt.Sprintf(` + resource "azure_instance" "foo" { + name = "%s" + image = "Ubuntu Server 14.04 LTS" + size = "Basic_A1" + storage_service_name = "%s" + location = "West US" + username = "terraform" + password = "Pass!admin123" + } + + resource "azure_data_disk" "foo" { + lun = 0 + size = 10 + storage_service_name = "${azure_instance.foo.storage_service_name}" + virtual_machine = "${azure_instance.foo.id}" + }`, name, testAccStorageServiceName) } -resource "azure_data_disk" "foo" { - lun = 0 - size = 10 - storage_service_name = "${azure_instance.foo.storage_service_name}" - virtual_machine = "${azure_instance.foo.id}" -}`, testAccStorageServiceName) +func testAccAzureDataDisk_advanced(name string) string { + return fmt.Sprintf(` + resource "azure_instance" "foo" { + name = "%s" + image = "Ubuntu Server 14.04 LTS" + size = "Basic_A1" + storage_service_name = "%s" + location = "West US" + username = "terraform" + password = "Pass!admin123" + } -var testAccAzureDataDisk_advanced = fmt.Sprintf(` -resource "azure_instance" "foo" { - name = "terraform-test1" - image = "Ubuntu Server 14.04 LTS" - size = "Basic_A1" - storage_service_name = "%s" - location = "West US" - username = "terraform" - password = "Pass!admin123" + resource "azure_data_disk" "foo" { + lun = 1 + size = 10 + caching = "ReadOnly" + storage_service_name = "${azure_instance.foo.storage_service_name}" + virtual_machine = "${azure_instance.foo.id}" + }`, name, testAccStorageServiceName) } -resource "azure_data_disk" "foo" { - lun = 1 - size = 10 - caching = "ReadOnly" - storage_service_name = "${azure_instance.foo.storage_service_name}" - virtual_machine = "${azure_instance.foo.id}" -}`, testAccStorageServiceName) +func testAccAzureDataDisk_update(name string) string { + return fmt.Sprintf(` + resource "azure_instance" "foo" { + name = "%s" + image = "Ubuntu Server 14.04 LTS" + size = "Basic_A1" + storage_service_name = "%s" + location = "West US" + username = "terraform" + password = "Pass!admin123" + } -var testAccAzureDataDisk_update = fmt.Sprintf(` -resource "azure_instance" "foo" { - name = "terraform-test1" - image = "Ubuntu Server 14.04 LTS" - size = "Basic_A1" - storage_service_name = "%s" - location = "West US" - username = "terraform" - password = "Pass!admin123" + resource "azure_instance" "bar" { + name = "terraform-test2" + image = "Ubuntu Server 14.04 LTS" + size = "Basic_A1" + storage_service_name = "${azure_instance.foo.storage_service_name}" + location = "West US" + username = "terraform" + password = "Pass!admin123" + } + + resource "azure_data_disk" "foo" { + lun = 2 + size = 20 + caching = "ReadWrite" + storage_service_name = "${azure_instance.bar.storage_service_name}" + virtual_machine = "${azure_instance.bar.id}" + }`, name, testAccStorageServiceName) } - -resource "azure_instance" "bar" { - name = "terraform-test2" - image = "Ubuntu Server 14.04 LTS" - size = "Basic_A1" - storage_service_name = "${azure_instance.foo.storage_service_name}" - location = "West US" - username = "terraform" - password = "Pass!admin123" -} - -resource "azure_data_disk" "foo" { - lun = 2 - size = 20 - caching = "ReadWrite" - storage_service_name = "${azure_instance.bar.storage_service_name}" - virtual_machine = "${azure_instance.bar.id}" -}`, testAccStorageServiceName) diff --git a/builtin/providers/azure/resource_azure_instance_test.go b/builtin/providers/azure/resource_azure_instance_test.go index 79e712154..7e63486c3 100644 --- a/builtin/providers/azure/resource_azure_instance_test.go +++ b/builtin/providers/azure/resource_azure_instance_test.go @@ -446,7 +446,7 @@ resource "azure_security_group_rule" "foo" { resource "azure_instance" "foo" { name = "terraform-test1" - image = "Windows Server 2012 R2 Datacenter, April 2015" + image = "Windows Server 2012 R2 Datacenter, September 2015" size = "Basic_A1" storage_service_name = "%s" location = "West US" @@ -520,7 +520,7 @@ resource "azure_security_group_rule" "bar" { resource "azure_instance" "foo" { name = "terraform-test1" - image = "Windows Server 2012 R2 Datacenter, April 2015" + image = "Windows Server 2012 R2 Datacenter, September 2015" size = "Basic_A2" storage_service_name = "%s" location = "West US"