Files
dns-autoresolver/internal/model/txt_test.go
T
2026-11-02 17:37:51 +07:00

31 lines
765 B
Go

package model
import (
"strings"
"testing"
)
func TestQuoteTXTAndPayloadRoundTrip(t *testing.T) {
long := "v=DKIM1; p=" + strings.Repeat("A", 400)
for _, v := range []string{"v=spf1 ~all", long, `a"b\c`} {
q := QuoteTXT(v)
if !strings.HasPrefix(q, `"`) {
t.Fatalf("not quoted: %q", q)
}
if got := TXTPayload(q); got != v {
t.Fatalf("roundtrip: got %q want %q", got, v)
}
if TXTPayload(v) != v && !strings.HasPrefix(v, `"`) {
t.Fatalf("unquoted payload changed")
}
}
if QuoteTXT(`"x"`) != `"x"` {
t.Fatal("quoted must pass through")
}
a := Record{Type: TXT, Values: []string{"v=DKIM1; k=rsa"}}
b := Record{Type: TXT, Values: []string{`"v=DKIM1; k=rsa"`}}
if !a.Equal(b) {
t.Fatal("quoted and unquoted must compare equal")
}
}