Skip to content

Commit

Permalink
Add import test to NS record
Browse files Browse the repository at this point in the history
  • Loading branch information
rosbo committed Dec 22, 2017
1 parent af2fb22 commit c82115e
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions google/resource_dns_record_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ func TestAccDnsRecordSet_basic(t *testing.T) {
t.Parallel()

zoneName := acctest.RandomWithPrefix("dnszone-test")
recordName := acctest.RandomWithPrefix("record-test")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDnsRecordSetDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDnsRecordSet_basic(zoneName, recordName, "127.0.0.10", 300),
Config: testAccDnsRecordSet_basic(zoneName, "127.0.0.10", 300),
Check: resource.ComposeTestCheckFunc(
testAccCheckDnsRecordSetExists(
"google_dns_record_set.foobar", zoneName),
),
},
resource.TestStep{
ResourceName: "google_dns_record_set.foobar",
ImportStateId: fmt.Sprintf("%s/%s.hashicorptest.com./A", zoneName, recordName),
ImportStateId: fmt.Sprintf("%s/test-record.hashicorptest.com./A", zoneName),
ImportState: true,
ImportStateVerify: true,
},
Expand All @@ -40,28 +39,27 @@ func TestAccDnsRecordSet_modify(t *testing.T) {
t.Parallel()

zoneName := acctest.RandomWithPrefix("dnszone-test")
recordName := acctest.RandomWithPrefix("record-test")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDnsRecordSetDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDnsRecordSet_basic(zoneName, recordName, "127.0.0.10", 300),
Config: testAccDnsRecordSet_basic(zoneName, "127.0.0.10", 300),
Check: resource.ComposeTestCheckFunc(
testAccCheckDnsRecordSetExists(
"google_dns_record_set.foobar", zoneName),
),
},
resource.TestStep{
Config: testAccDnsRecordSet_basic(zoneName, recordName, "127.0.0.11", 300),
Config: testAccDnsRecordSet_basic(zoneName, "127.0.0.11", 300),
Check: resource.ComposeTestCheckFunc(
testAccCheckDnsRecordSetExists(
"google_dns_record_set.foobar", zoneName),
),
},
resource.TestStep{
Config: testAccDnsRecordSet_basic(zoneName, recordName, "127.0.0.11", 600),
Config: testAccDnsRecordSet_basic(zoneName, "127.0.0.11", 600),
Check: resource.ComposeTestCheckFunc(
testAccCheckDnsRecordSetExists(
"google_dns_record_set.foobar", zoneName),
Expand All @@ -75,21 +73,20 @@ func TestAccDnsRecordSet_changeType(t *testing.T) {
t.Parallel()

zoneName := acctest.RandomWithPrefix("dnszone-test")
recordName := acctest.RandomWithPrefix("record-test")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDnsRecordSetDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDnsRecordSet_basic(zoneName, recordName, "127.0.0.10", 300),
Config: testAccDnsRecordSet_basic(zoneName, "127.0.0.10", 300),
Check: resource.ComposeTestCheckFunc(
testAccCheckDnsRecordSetExists(
"google_dns_record_set.foobar", zoneName),
),
},
resource.TestStep{
Config: testAccDnsRecordSet_bigChange(zoneName, recordName, 600),
Config: testAccDnsRecordSet_bigChange(zoneName, 600),
Check: resource.ComposeTestCheckFunc(
testAccCheckDnsRecordSetExists(
"google_dns_record_set.foobar", zoneName),
Expand All @@ -113,6 +110,12 @@ func TestAccDnsRecordSet_ns(t *testing.T) {
"google_dns_record_set.foobar", zoneName),
),
},
resource.TestStep{
ResourceName: "google_dns_record_set.foobar",
ImportStateId: fmt.Sprintf("%s/hashicorptest.com./NS", zoneName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -185,7 +188,7 @@ func testAccCheckDnsRecordSetExists(resourceType, resourceName string) resource.
}
}

func testAccDnsRecordSet_basic(zoneName, recordName, addr2 string, ttl int) string {
func testAccDnsRecordSet_basic(zoneName, addr2 string, ttl int) string {
return fmt.Sprintf(`
resource "google_dns_managed_zone" "parent-zone" {
name = "%s"
Expand All @@ -194,12 +197,12 @@ func testAccDnsRecordSet_basic(zoneName, recordName, addr2 string, ttl int) stri
}
resource "google_dns_record_set" "foobar" {
managed_zone = "${google_dns_managed_zone.parent-zone.name}"
name = "%s.${google_dns_managed_zone.parent-zone.dns_name}"
name = "test-record.${google_dns_managed_zone.parent-zone.dns_name}"
type = "A"
rrdatas = ["127.0.0.1", "%s"]
ttl = %d
}
`, zoneName, recordName, addr2, ttl)
`, zoneName, addr2, ttl)
}

func testAccDnsRecordSet_ns(name string, ttl int) string {
Expand Down Expand Up @@ -236,7 +239,7 @@ func testAccDnsRecordSet_nestedNS(name string, ttl int) string {
`, name, ttl)
}

func testAccDnsRecordSet_bigChange(zoneName, recordName string, ttl int) string {
func testAccDnsRecordSet_bigChange(zoneName string, ttl int) string {
return fmt.Sprintf(`
resource "google_dns_managed_zone" "parent-zone" {
name = "%s"
Expand All @@ -245,10 +248,10 @@ func testAccDnsRecordSet_bigChange(zoneName, recordName string, ttl int) string
}
resource "google_dns_record_set" "foobar" {
managed_zone = "${google_dns_managed_zone.parent-zone.name}"
name = "%s.${google_dns_managed_zone.parent-zone.dns_name}"
name = "test-record.${google_dns_managed_zone.parent-zone.dns_name}"
type = "CNAME"
rrdatas = ["www.terraform.io."]
ttl = %d
}
`, zoneName, recordName, ttl)
`, zoneName, ttl)
}

0 comments on commit c82115e

Please sign in to comment.