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.
This commit is contained in:
James Nugent 2016-02-03 13:11:47 -05:00
parent 8c8b39d15d
commit ef350af219
2 changed files with 27 additions and 13 deletions

View File

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

View File

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