mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-11-13 03:34:32 +08:00
de4455942b
* Replace RecordConfig.Name and .NameFQDN with getters and setters. * Replace RecordConfig.Target with getters and setters. * Eliminate the CombinedTarget concept. * Add RecordConfig.PopulateFromString to reduce code in all providers. * encode and decode name.com txt records (#315) * Replace fmt.Errorf with errors.Errorf
79 lines
1.5 KiB
Go
79 lines
1.5 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
|
|
}{
|
|
{`foo`, `foo`, []string{`foo`}},
|
|
{`"foo"`, `foo`, []string{`foo`}},
|
|
{`"foo bar"`, `foo bar`, []string{`foo bar`}},
|
|
{`foo bar`, `foo bar`, []string{`foo bar`}},
|
|
{`"aaa" "bbb"`, `aaa`, []string{`aaa`, `bbb`}},
|
|
}
|
|
for i, test := range tests {
|
|
ls := ParseQuotedTxt(test.d1)
|
|
if ls[0] != test.e1 {
|
|
t.Errorf("%v: expected Target=(%v) got (%v)", i, test.e1, ls[0])
|
|
}
|
|
if len(ls) != len(test.e2) {
|
|
t.Errorf("%v: expected TxtStrings=(%v) got (%v)", i, test.e2, ls)
|
|
}
|
|
for i := range ls {
|
|
if len(ls[i]) != len(test.e2[i]) {
|
|
t.Errorf("%v: expected TxtStrings=(%v) got (%v)", i, test.e2, ls)
|
|
}
|
|
}
|
|
}
|
|
}
|