From ef350af2198e71057abf99b794bd44eebf51de33 Mon Sep 17 00:00:00 2001 From: James Nugent Date: Wed, 3 Feb 2016 13:11:47 -0500 Subject: [PATCH] provider/azure: Randomize name in acceptance tests This should address the failures seen in Travis Build Run #8774. It is likely there are others which also need addressing - they will be addressed on a case-by-case basis as they come up. --- .../resource_azure_hosted_service_test.go | 25 +++++++++++++------ .../azure/resource_azure_instance_test.go | 15 +++++++---- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/builtin/providers/azure/resource_azure_hosted_service_test.go b/builtin/providers/azure/resource_azure_hosted_service_test.go index bbad19632..fb1a71934 100644 --- a/builtin/providers/azure/resource_azure_hosted_service_test.go +++ b/builtin/providers/azure/resource_azure_hosted_service_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -11,16 +12,19 @@ import ( func TestAccAzureHostedServiceBasic(t *testing.T) { name := "azure_hosted_service.foo" + hostedServiceName := fmt.Sprintf("terraform-testing-service%d", acctest.RandInt()) + config := fmt.Sprintf(testAccAzureHostedServiceBasic, hostedServiceName) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAzureHostedServiceDestroyed, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAzureHostedServiceBasic, + Config: config, Check: resource.ComposeTestCheckFunc( testAccCheckAzureHostedServiceExists(name), - resource.TestCheckResourceAttr(name, "name", "terraform-testing-service"), + resource.TestCheckResourceAttr(name, "name", hostedServiceName), resource.TestCheckResourceAttr(name, "location", "North Europe"), resource.TestCheckResourceAttr(name, "ephemeral_contents", "false"), resource.TestCheckResourceAttr(name, "description", "very discriptive"), @@ -34,16 +38,21 @@ func TestAccAzureHostedServiceBasic(t *testing.T) { func TestAccAzureHostedServiceUpdate(t *testing.T) { name := "azure_hosted_service.foo" + hostedServiceName := fmt.Sprintf("terraform-testing-service%d", acctest.RandInt()) + + basicConfig := fmt.Sprintf(testAccAzureHostedServiceBasic, hostedServiceName) + updateConfig := fmt.Sprintf(testAccAzureHostedServiceUpdate, hostedServiceName) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAzureHostedServiceDestroyed, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAzureHostedServiceBasic, + Config: basicConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAzureHostedServiceExists(name), - resource.TestCheckResourceAttr(name, "name", "terraform-testing-service"), + resource.TestCheckResourceAttr(name, "name", hostedServiceName), resource.TestCheckResourceAttr(name, "location", "North Europe"), resource.TestCheckResourceAttr(name, "ephemeral_contents", "false"), resource.TestCheckResourceAttr(name, "description", "very discriptive"), @@ -52,10 +61,10 @@ func TestAccAzureHostedServiceUpdate(t *testing.T) { }, resource.TestStep{ - Config: testAccAzureHostedServiceUpdate, + Config: updateConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAzureHostedServiceExists(name), - resource.TestCheckResourceAttr(name, "name", "terraform-testing-service"), + resource.TestCheckResourceAttr(name, "name", hostedServiceName), resource.TestCheckResourceAttr(name, "location", "North Europe"), resource.TestCheckResourceAttr(name, "ephemeral_contents", "true"), resource.TestCheckResourceAttr(name, "description", "very discriptive"), @@ -105,7 +114,7 @@ func testAccCheckAzureHostedServiceDestroyed(s *terraform.State) error { const testAccAzureHostedServiceBasic = ` resource "azure_hosted_service" "foo" { - name = "terraform-testing-service" + name = "%s" location = "North Europe" ephemeral_contents = false description = "very discriptive" @@ -114,7 +123,7 @@ resource "azure_hosted_service" "foo" { ` const testAccAzureHostedServiceUpdate = ` resource "azure_hosted_service" "foo" { - name = "terraform-testing-service" + name = "%s" location = "North Europe" ephemeral_contents = true description = "very discriptive" diff --git a/builtin/providers/azure/resource_azure_instance_test.go b/builtin/providers/azure/resource_azure_instance_test.go index adbd5bfd9..51ca0f5eb 100644 --- a/builtin/providers/azure/resource_azure_instance_test.go +++ b/builtin/providers/azure/resource_azure_instance_test.go @@ -8,6 +8,7 @@ import ( "github.com/Azure/azure-sdk-for-go/management" "github.com/Azure/azure-sdk-for-go/management/virtualmachine" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -46,21 +47,25 @@ func TestAccAzureInstance_basic(t *testing.T) { func TestAccAzureInstance_separateHostedService(t *testing.T) { var dpmt virtualmachine.DeploymentResponse + hostedServiceName := fmt.Sprintf("terraform-testing-service%d", acctest.RandInt()) + + config := fmt.Sprintf(testAccAzureInstance_separateHostedService, hostedServiceName, instanceName, testAccStorageServiceName) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, CheckDestroy: testAccCheckAzureInstanceDestroyed(testAccHostedServiceName), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccAzureInstance_separateHostedService, + Config: config, Check: resource.ComposeTestCheckFunc( testAccCheckAzureInstanceExists( - "azure_instance.foo", testAccHostedServiceName, &dpmt), + "azure_instance.foo", hostedServiceName, &dpmt), testAccCheckAzureInstanceBasicAttributes(&dpmt), resource.TestCheckResourceAttr( "azure_instance.foo", "name", instanceName), resource.TestCheckResourceAttr( - "azure_instance.foo", "hosted_service_name", "terraform-testing-service"), + "azure_instance.foo", "hosted_service_name", hostedServiceName), resource.TestCheckResourceAttr( "azure_instance.foo", "location", "West US"), resource.TestCheckResourceAttr( @@ -441,7 +446,7 @@ resource "azure_instance" "foo" { } }`, instanceName, testAccStorageServiceName) -var testAccAzureInstance_separateHostedService = fmt.Sprintf(` +var testAccAzureInstance_separateHostedService = ` resource "azure_hosted_service" "foo" { name = "%s" location = "West US" @@ -464,7 +469,7 @@ resource "azure_instance" "foo" { public_port = 22 private_port = 22 } -}`, testAccHostedServiceName, instanceName, testAccStorageServiceName) +}` var testAccAzureInstance_advanced = fmt.Sprintf(` resource "azure_virtual_network" "foo" {