add test for dns TXT record set

This commit is contained in:
S. Brent Faulkner 2017-05-07 11:42:54 -04:00
parent 571ee96d96
commit 8165e2e96f
2 changed files with 98 additions and 0 deletions

View File

@ -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),
),
},
},
})
}
}

View File

@ -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)
}
}