Skip to content

Commit

Permalink
Use different random strings for each compute address acctest config
Browse files Browse the repository at this point in the history
This avoids naming collisions when running multiple tests in parallel.
  • Loading branch information
Nic Cope committed Oct 30, 2017
1 parent 7cf5f35 commit 1e2ca95
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
5 changes: 3 additions & 2 deletions google/import_compute_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package google
import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

Expand All @@ -17,7 +18,7 @@ func TestAccComputeAddress_importBasic(t *testing.T) {
CheckDestroy: testAccCheckComputeAddressDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeAddress_basic,
Config: testAccComputeAddress_basic(acctest.RandString(10)),
},

resource.TestStep{
Expand All @@ -40,7 +41,7 @@ func TestAccComputeAddress_importInternal(t *testing.T) {
CheckDestroy: testAccCheckComputeAddressDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeAddress_internal,
Config: testAccComputeAddress_internal(acctest.RandString(10)),
},

resource.TestStep{
Expand Down
32 changes: 18 additions & 14 deletions google/resource_compute_address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestAccComputeAddress_basic(t *testing.T) {
CheckDestroy: testAccCheckComputeAddressDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeAddress_basic,
Config: testAccComputeAddress_basic(acctest.RandString(10)),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeAddressExists(
"google_compute_address.foobar", &addr),
Expand All @@ -105,7 +105,7 @@ func TestAccComputeAddress_internal(t *testing.T) {
CheckDestroy: testAccCheckComputeAddressDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccComputeAddress_internal,
Config: testAccComputeAddress_internal(acctest.RandString(10)),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeBetaAddressExists("google_compute_address.internal", &addr),
testAccCheckComputeBetaAddressExists("google_compute_address.internal_with_subnet", &addr),
Expand Down Expand Up @@ -202,14 +202,17 @@ func testAccCheckComputeBetaAddressExists(n string, addr *computeBeta.Address) r
}
}

var testAccComputeAddress_basic = fmt.Sprintf(`
func testAccComputeAddress_basic(i string) string {
return fmt.Sprintf(`
resource "google_compute_address" "foobar" {
name = "address-test-%s"
}`, acctest.RandString(10))
}`, i)
}

var testAccComputeAddress_internal = fmt.Sprintf(`
func testAccComputeAddress_internal(i string) string {
return fmt.Sprintf(`
resource "google_compute_address" "internal" {
name = "address-test-%s"
name = "address-test-internal-%s"
address_type = "INTERNAL"
region = "us-east1"
}
Expand All @@ -226,7 +229,7 @@ resource "google_compute_subnetwork" "foo" {
}
resource "google_compute_address" "internal_with_subnet" {
name = "address-test-%s"
name = "address-test-internal-with-subnet-%s"
subnetwork = "${google_compute_subnetwork.foo.self_link}"
address_type = "INTERNAL"
region = "us-east1"
Expand All @@ -235,15 +238,16 @@ resource "google_compute_address" "internal_with_subnet" {
// We can't test the address alone, because we don't know what IP range the
// default subnetwork uses.
resource "google_compute_address" "internal_with_subnet_and_address" {
name = "address-test-%s"
name = "address-test-internal-with-subnet-and-address-%s"
subnetwork = "${google_compute_subnetwork.foo.self_link}"
address_type = "INTERNAL"
address = "10.0.42.42"
region = "us-east1"
}`,
acctest.RandString(10), // google_compute_address.internal name
acctest.RandString(10), // google_compute_network.default name
acctest.RandString(10), // google_compute_subnetwork.foo name
acctest.RandString(10), // google_compute_address.internal_with_subnet_name
acctest.RandString(10), // google_compute_address.internal_with_subnet_and_address name
)
i, // google_compute_address.internal name
i, // google_compute_network.default name
i, // google_compute_subnetwork.foo name
i, // google_compute_address.internal_with_subnet_name
i, // google_compute_address.internal_with_subnet_and_address name
)
}

0 comments on commit 1e2ca95

Please sign in to comment.