Fix record id parsing for hyphened hostnames (#5228)

This commit is contained in:
Dmytro Aleksandrov 2016-02-20 12:08:43 +02:00
parent 92dc20bb35
commit 6886b75425
2 changed files with 32 additions and 3 deletions

View File

@ -91,17 +91,19 @@ type errorResponse struct {
ErrorMsg string `json:"error"`
}
const idSeparator string = ":::"
func (record *Record) Id() string {
return fmt.Sprintf("%s-%s", record.Name, record.Type)
return record.Name + idSeparator + record.Type
}
func (rrSet *ResourceRecordSet) Id() string {
return fmt.Sprintf("%s-%s", rrSet.Name, rrSet.Type)
return rrSet.Name + idSeparator + rrSet.Type
}
// Returns name and type of record or record set based on it's ID
func parseId(recId string) (string, string, error) {
s := strings.Split(recId, "-")
s := strings.Split(recId, idSeparator)
if len(s) == 2 {
return s[0], s[1], nil
} else {

View File

@ -24,6 +24,23 @@ func TestAccPDNSRecord_A(t *testing.T) {
})
}
func TestAccPDNSRecord_WithCount(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
{
Config: testPDNSRecordConfigHyphenedWithCount,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-counted.0"),
testAccCheckPDNSRecordExists("powerdns_record.test-counted.1"),
),
},
},
})
}
func TestAccPDNSRecord_AAAA(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -262,6 +279,16 @@ resource "powerdns_record" "test-a" {
records = [ "1.1.1.1", "2.2.2.2" ]
}`
const testPDNSRecordConfigHyphenedWithCount = `
resource "powerdns_record" "test-counted" {
count = "2"
zone = "sysa.xyz"
name = "redis-${count.index}.sysa.xyz"
type = "A"
ttl = 60
records = [ "1.1.1.${count.index}" ]
}`
const testPDNSRecordConfigAAAA = `
resource "powerdns_record" "test-aaaa" {
zone = "sysa.xyz"