provider/digitalocean: prevent collision on domain acctest

This commit is contained in:
Paul Hinze 2016-01-04 16:34:31 -06:00
parent 983b34291d
commit adf4280aff
1 changed files with 9 additions and 7 deletions

View File

@ -5,12 +5,14 @@ import (
"testing" "testing"
"github.com/digitalocean/godo" "github.com/digitalocean/godo"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
func TestAccDigitalOceanDomain_Basic(t *testing.T) { func TestAccDigitalOceanDomain_Basic(t *testing.T) {
var domain godo.Domain var domain godo.Domain
domainName := fmt.Sprintf("foobar-test-terraform-%s.com", acctest.RandString(10))
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -18,12 +20,12 @@ func TestAccDigitalOceanDomain_Basic(t *testing.T) {
CheckDestroy: testAccCheckDigitalOceanDomainDestroy, CheckDestroy: testAccCheckDigitalOceanDomainDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccCheckDigitalOceanDomainConfig_basic, Config: fmt.Sprintf(testAccCheckDigitalOceanDomainConfig_basic, domainName),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanDomainExists("digitalocean_domain.foobar", &domain), testAccCheckDigitalOceanDomainExists("digitalocean_domain.foobar", &domain),
testAccCheckDigitalOceanDomainAttributes(&domain), testAccCheckDigitalOceanDomainAttributes(&domain, domainName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"digitalocean_domain.foobar", "name", "foobar-test-terraform.com"), "digitalocean_domain.foobar", "name", domainName),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
"digitalocean_domain.foobar", "ip_address", "192.168.0.10"), "digitalocean_domain.foobar", "ip_address", "192.168.0.10"),
), ),
@ -51,10 +53,10 @@ func testAccCheckDigitalOceanDomainDestroy(s *terraform.State) error {
return nil return nil
} }
func testAccCheckDigitalOceanDomainAttributes(domain *godo.Domain) resource.TestCheckFunc { func testAccCheckDigitalOceanDomainAttributes(domain *godo.Domain, name string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
if domain.Name != "foobar-test-terraform.com" { if domain.Name != name {
return fmt.Errorf("Bad name: %s", domain.Name) return fmt.Errorf("Bad name: %s", domain.Name)
} }
@ -94,6 +96,6 @@ func testAccCheckDigitalOceanDomainExists(n string, domain *godo.Domain) resourc
const testAccCheckDigitalOceanDomainConfig_basic = ` const testAccCheckDigitalOceanDomainConfig_basic = `
resource "digitalocean_domain" "foobar" { resource "digitalocean_domain" "foobar" {
name = "foobar-test-terraform.com" name = "%s"
ip_address = "192.168.0.10" ip_address = "192.168.0.10"
}` }`