dnscontrol/providers/powerdns/convert_test.go
Tom Limoncelli cbccbbeb8d
REFACTOR: Opinion: TXT records are one long string (#2631)
Co-authored-by: Costas Drogos <costas.drogos@gmail.com>
Co-authored-by: imlonghao <git@imlonghao.com>
Co-authored-by: Jeffrey Cafferata <jeffrey@jcid.nl>
Co-authored-by: Vincent Hagen <blackshadev@users.noreply.github.com>
2023-12-04 17:45:25 -05:00

54 lines
2.2 KiB
Go

package powerdns
import (
"fmt"
"strings"
"testing"
"github.com/mittwald/go-powerdns/apis/zones"
"github.com/stretchr/testify/assert"
)
func TestToRecordConfig(t *testing.T) {
record := zones.Record{
Content: "simple",
}
recordConfig, err := toRecordConfig("example.com", record, 120, "test", "TXT")
assert.NoError(t, err)
assert.Equal(t, "test.example.com", recordConfig.NameFQDN)
assert.Equal(t, "\"simple\"", recordConfig.String())
assert.Equal(t, uint32(120), recordConfig.TTL)
assert.Equal(t, "TXT", recordConfig.Type)
largeContent := fmt.Sprintf("\"%s\" \"%s\"", strings.Repeat("A", 300), strings.Repeat("B", 300))
largeRecord := zones.Record{
Content: largeContent,
}
recordConfig, err = toRecordConfig("example.com", largeRecord, 5, "large", "TXT")
assert.NoError(t, err)
assert.Equal(t, "large.example.com", recordConfig.NameFQDN)
assert.Equal(t, `"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"`,
recordConfig.String())
assert.Equal(t, uint32(5), recordConfig.TTL)
assert.Equal(t, "TXT", recordConfig.Type)
}
func TestParseText(t *testing.T) {
// short TXT record
short := parseTxt("\"simple\"")
assert.Equal(t, []string{"simple"}, short)
// TXT record with multiple parts
multiple := parseTxt("\"simple\" \"simple2\"")
assert.Equal(t, []string{"simple", "simple2"}, multiple)
// long TXT record
long := parseTxt(fmt.Sprintf("\"%s\"", strings.Repeat("A", 300)))
assert.Equal(t, []string{strings.Repeat("A", 300)}, long)
// multiple long TXT record
multipleLong := parseTxt(fmt.Sprintf("\"%s\" \"%s\"", strings.Repeat("A", 300), strings.Repeat("B", 300)))
assert.Equal(t, []string{strings.Repeat("A", 300), strings.Repeat("B", 300)}, multipleLong)
}