diff --git a/builtin/providers/dns/data_dns_txt_record_set_test.go b/builtin/providers/dns/data_dns_txt_record_set_test.go new file mode 100644 index 000000000..6958ee269 --- /dev/null +++ b/builtin/providers/dns/data_dns_txt_record_set_test.go @@ -0,0 +1,59 @@ +package dns + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccDataDnsTxtRecordSet_Basic(t *testing.T) { + tests := []struct { + DataSourceBlock string + DataSourceName string + Expected []string + Host string + }{ + { + ` + data "dns_txt_record_set" "foo" { + host = "hashicorp.com" + } + `, + "foo", + []string{ + "google-site-verification=oqoe6Z7OB_726BNm33g4OdKK57KDtCfH266f8wAvLBo", + "v=spf1 include:_spf.google.com include:spf.mail.intercom.io include:stspg-customer.com include:mail.zendesk.com ~all", + "status-page-domain-verification=dgtdvzlp8tfn", + }, + "hashicorp.com", + }, + } + + for _, test := range tests { + recordName := fmt.Sprintf("data.dns_txt_record_set.%s", test.DataSourceName) + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: test.DataSourceBlock, + Check: resource.ComposeTestCheckFunc( + testCheckAttrStringArray(recordName, "records", test.Expected), + ), + }, + resource.TestStep{ + Config: test.DataSourceBlock, + Check: resource.ComposeTestCheckFunc( + testCheckAttrStringArrayMember(recordName, "record", test.Expected), + ), + }, + resource.TestStep{ + Config: test.DataSourceBlock, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(recordName, "id", test.Host), + ), + }, + }, + }) + } +} diff --git a/builtin/providers/dns/test_check_attr_string_array_member.go b/builtin/providers/dns/test_check_attr_string_array_member.go new file mode 100644 index 000000000..e246ed32e --- /dev/null +++ b/builtin/providers/dns/test_check_attr_string_array_member.go @@ -0,0 +1,39 @@ +package dns + +import ( + "fmt" + + r "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func testCheckAttrStringArrayMember(name, key string, value []string) r.TestCheckFunc { + return func(s *terraform.State) error { + ms := s.RootModule() + rs, ok := ms.Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + is := rs.Primary + if is == nil { + return fmt.Errorf("No primary instance: %s", name) + } + + got, ok := is.Attributes[key] + if !ok { + return fmt.Errorf("Attributes not found for %s", key) + } + + for _, want := range value { + if got == want { + return nil + } + } + + return fmt.Errorf( + "Unexpected value for %s: got %s", + key, + got) + } +}