dnscontrol/models/txt_test.go
Tom Limoncelli de88bfe8b7
Add support for TXT records with multiple strings (BIND, ROUTE53) (#293)
* BIND: Support TXT records with multiple strings (#289)
* ROUTE53: Add support for TXT records with multiple strings (#292)
2018-01-04 19:19:35 -05:00

72 lines
1.3 KiB
Go

package models
import (
"testing"
)
func TestIsQuoted(t *testing.T) {
tests := []struct {
d1 string
e1 bool
}{
{``, false},
{`foo`, false},
{`""`, true},
{`"a"`, true},
{`"bb"`, true},
{`"ccc"`, true},
{`"aaa" "bbb"`, true},
}
for i, test := range tests {
r := IsQuoted(test.d1)
if r != test.e1 {
t.Errorf("%v: expected (%v) got (%v)", i, test.e1, r)
}
}
}
func TestStripQuotes(t *testing.T) {
tests := []struct {
d1 string
e1 string
}{
{``, ``},
{`a`, `a`},
{`bb`, `bb`},
{`ccc`, `ccc`},
{`dddd`, `dddd`},
{`"A"`, `A`},
{`"BB"`, `BB`},
{`"CCC"`, `CCC`},
{`"DDDD"`, `DDDD`},
{`"EEEEE"`, `EEEEE`},
{`"aaa" "bbb"`, `aaa" "bbb`},
}
for i, test := range tests {
r := StripQuotes(test.d1)
if r != test.e1 {
t.Errorf("%v: expected (%v) got (%v)", i, test.e1, r)
}
}
}
func TestSetTxtParse(t *testing.T) {
tests := []struct {
d1 string
e1 string
e2 []string
}{
{``, ``, []string{``}},
{`foo`, `foo`, []string{`foo`}},
{`"foo"`, `foo`, []string{`foo`}},
{`"aaa" "bbb"`, `aaa`, []string{`aaa`, `bbb`}},
}
for i, test := range tests {
x := &RecordConfig{Type: "TXT"}
x.SetTxtParse(test.d1)
if x.Target != test.e1 {
t.Errorf("%v: expected Target=(%v) got (%v)", i, test.e1, x.Target)
}
}
}