Skip to content

Commit ef350af

Browse files
committed
provider/azure: Randomize name in acceptance tests
This should address the failures seen in Travis Build Run hashicorp#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.
1 parent 8c8b39d commit ef350af

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

builtin/providers/azure/resource_azure_hosted_service_test.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,27 @@ import (
44
"fmt"
55
"testing"
66

7+
"github.com/hashicorp/terraform/helper/acctest"
78
"github.com/hashicorp/terraform/helper/resource"
89
"github.com/hashicorp/terraform/terraform"
910
)
1011

1112
func TestAccAzureHostedServiceBasic(t *testing.T) {
1213
name := "azure_hosted_service.foo"
1314

15+
hostedServiceName := fmt.Sprintf("terraform-testing-service%d", acctest.RandInt())
16+
config := fmt.Sprintf(testAccAzureHostedServiceBasic, hostedServiceName)
17+
1418
resource.Test(t, resource.TestCase{
1519
PreCheck: func() { testAccPreCheck(t) },
1620
Providers: testAccProviders,
1721
CheckDestroy: testAccCheckAzureHostedServiceDestroyed,
1822
Steps: []resource.TestStep{
1923
resource.TestStep{
20-
Config: testAccAzureHostedServiceBasic,
24+
Config: config,
2125
Check: resource.ComposeTestCheckFunc(
2226
testAccCheckAzureHostedServiceExists(name),
23-
resource.TestCheckResourceAttr(name, "name", "terraform-testing-service"),
27+
resource.TestCheckResourceAttr(name, "name", hostedServiceName),
2428
resource.TestCheckResourceAttr(name, "location", "North Europe"),
2529
resource.TestCheckResourceAttr(name, "ephemeral_contents", "false"),
2630
resource.TestCheckResourceAttr(name, "description", "very discriptive"),
@@ -34,16 +38,21 @@ func TestAccAzureHostedServiceBasic(t *testing.T) {
3438
func TestAccAzureHostedServiceUpdate(t *testing.T) {
3539
name := "azure_hosted_service.foo"
3640

41+
hostedServiceName := fmt.Sprintf("terraform-testing-service%d", acctest.RandInt())
42+
43+
basicConfig := fmt.Sprintf(testAccAzureHostedServiceBasic, hostedServiceName)
44+
updateConfig := fmt.Sprintf(testAccAzureHostedServiceUpdate, hostedServiceName)
45+
3746
resource.Test(t, resource.TestCase{
3847
PreCheck: func() { testAccPreCheck(t) },
3948
Providers: testAccProviders,
4049
CheckDestroy: testAccCheckAzureHostedServiceDestroyed,
4150
Steps: []resource.TestStep{
4251
resource.TestStep{
43-
Config: testAccAzureHostedServiceBasic,
52+
Config: basicConfig,
4453
Check: resource.ComposeTestCheckFunc(
4554
testAccCheckAzureHostedServiceExists(name),
46-
resource.TestCheckResourceAttr(name, "name", "terraform-testing-service"),
55+
resource.TestCheckResourceAttr(name, "name", hostedServiceName),
4756
resource.TestCheckResourceAttr(name, "location", "North Europe"),
4857
resource.TestCheckResourceAttr(name, "ephemeral_contents", "false"),
4958
resource.TestCheckResourceAttr(name, "description", "very discriptive"),
@@ -52,10 +61,10 @@ func TestAccAzureHostedServiceUpdate(t *testing.T) {
5261
},
5362

5463
resource.TestStep{
55-
Config: testAccAzureHostedServiceUpdate,
64+
Config: updateConfig,
5665
Check: resource.ComposeTestCheckFunc(
5766
testAccCheckAzureHostedServiceExists(name),
58-
resource.TestCheckResourceAttr(name, "name", "terraform-testing-service"),
67+
resource.TestCheckResourceAttr(name, "name", hostedServiceName),
5968
resource.TestCheckResourceAttr(name, "location", "North Europe"),
6069
resource.TestCheckResourceAttr(name, "ephemeral_contents", "true"),
6170
resource.TestCheckResourceAttr(name, "description", "very discriptive"),
@@ -105,7 +114,7 @@ func testAccCheckAzureHostedServiceDestroyed(s *terraform.State) error {
105114

106115
const testAccAzureHostedServiceBasic = `
107116
resource "azure_hosted_service" "foo" {
108-
name = "terraform-testing-service"
117+
name = "%s"
109118
location = "North Europe"
110119
ephemeral_contents = false
111120
description = "very discriptive"
@@ -114,7 +123,7 @@ resource "azure_hosted_service" "foo" {
114123
`
115124
const testAccAzureHostedServiceUpdate = `
116125
resource "azure_hosted_service" "foo" {
117-
name = "terraform-testing-service"
126+
name = "%s"
118127
location = "North Europe"
119128
ephemeral_contents = true
120129
description = "very discriptive"

builtin/providers/azure/resource_azure_instance_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/Azure/azure-sdk-for-go/management"
1010
"github.com/Azure/azure-sdk-for-go/management/virtualmachine"
11+
"github.com/hashicorp/terraform/helper/acctest"
1112
"github.com/hashicorp/terraform/helper/resource"
1213
"github.com/hashicorp/terraform/terraform"
1314
)
@@ -46,21 +47,25 @@ func TestAccAzureInstance_basic(t *testing.T) {
4647
func TestAccAzureInstance_separateHostedService(t *testing.T) {
4748
var dpmt virtualmachine.DeploymentResponse
4849

50+
hostedServiceName := fmt.Sprintf("terraform-testing-service%d", acctest.RandInt())
51+
52+
config := fmt.Sprintf(testAccAzureInstance_separateHostedService, hostedServiceName, instanceName, testAccStorageServiceName)
53+
4954
resource.Test(t, resource.TestCase{
5055
PreCheck: func() { testAccPreCheck(t) },
5156
Providers: testAccProviders,
5257
CheckDestroy: testAccCheckAzureInstanceDestroyed(testAccHostedServiceName),
5358
Steps: []resource.TestStep{
5459
resource.TestStep{
55-
Config: testAccAzureInstance_separateHostedService,
60+
Config: config,
5661
Check: resource.ComposeTestCheckFunc(
5762
testAccCheckAzureInstanceExists(
58-
"azure_instance.foo", testAccHostedServiceName, &dpmt),
63+
"azure_instance.foo", hostedServiceName, &dpmt),
5964
testAccCheckAzureInstanceBasicAttributes(&dpmt),
6065
resource.TestCheckResourceAttr(
6166
"azure_instance.foo", "name", instanceName),
6267
resource.TestCheckResourceAttr(
63-
"azure_instance.foo", "hosted_service_name", "terraform-testing-service"),
68+
"azure_instance.foo", "hosted_service_name", hostedServiceName),
6469
resource.TestCheckResourceAttr(
6570
"azure_instance.foo", "location", "West US"),
6671
resource.TestCheckResourceAttr(
@@ -441,7 +446,7 @@ resource "azure_instance" "foo" {
441446
}
442447
}`, instanceName, testAccStorageServiceName)
443448

444-
var testAccAzureInstance_separateHostedService = fmt.Sprintf(`
449+
var testAccAzureInstance_separateHostedService = `
445450
resource "azure_hosted_service" "foo" {
446451
name = "%s"
447452
location = "West US"
@@ -464,7 +469,7 @@ resource "azure_instance" "foo" {
464469
public_port = 22
465470
private_port = 22
466471
}
467-
}`, testAccHostedServiceName, instanceName, testAccStorageServiceName)
472+
}`
468473

469474
var testAccAzureInstance_advanced = fmt.Sprintf(`
470475
resource "azure_virtual_network" "foo" {

0 commit comments

Comments
 (0)