11package dns
22
33import (
4+ "fmt"
45 "testing"
56
67 "github.com/hashicorp/terraform/helper/resource"
@@ -9,6 +10,7 @@ import (
910func TestAccDataDnsCnameRecordSet_Basic (t * testing.T ) {
1011 tests := []struct {
1112 DataSourceBlock string
13+ DataSourceName string
1214 Expected string
1315 Host string
1416 }{
@@ -18,25 +20,39 @@ func TestAccDataDnsCnameRecordSet_Basic(t *testing.T) {
1820 host = "www.hashicorp.com"
1921 }
2022 ` ,
23+ "foo" ,
2124 "hashicorp.netlifyglobalcdn.com." ,
2225 "www.hashicorp.com" ,
2326 },
27+ {
28+ `
29+ data "dns_cname_record_set" "non-existent" {
30+ host = "jolly.roger"
31+ ignore_errors = true
32+ }
33+ ` ,
34+ "non-existent" ,
35+ "" ,
36+ "jolly.roger" ,
37+ },
2438 }
2539
2640 for _ , test := range tests {
41+ recordName := fmt .Sprintf ("data.dns_cname_record_set.%s" , test .DataSourceName )
42+
2743 resource .Test (t , resource.TestCase {
2844 Providers : testAccProviders ,
2945 Steps : []resource.TestStep {
3046 {
3147 Config : test .DataSourceBlock ,
3248 Check : resource .ComposeTestCheckFunc (
33- resource .TestCheckResourceAttr ("data.dns_cname_record_set.foo" , "cname" , test .Expected ),
49+ resource .TestCheckResourceAttr (recordName , "cname" , test .Expected ),
3450 ),
3551 },
3652 {
3753 Config : test .DataSourceBlock ,
3854 Check : resource .ComposeTestCheckFunc (
39- resource .TestCheckResourceAttr ("data.dns_cname_record_set.foo" , "id" , test .Host ),
55+ resource .TestCheckResourceAttr (recordName , "id" , test .Host ),
4056 ),
4157 },
4258 },
0 commit comments