pull/18/head
Hugo Landau 10 years ago
parent 9867373039
commit c0fe9971cd

@ -4,33 +4,29 @@ import "testing"
import "github.com/hlandau/ncdns/util" import "github.com/hlandau/ncdns/util"
type item struct { type item struct {
input string input string
expectedHead string expectedHead string
expectedRest string expectedRest string
expectedError error
} }
var items = []item{ var items = []item{
item{"", "", "", nil}, item{"", "", ""},
item{"a", "a", "", nil}, item{"a", "a", ""},
item{"alpha", "alpha", "", nil}, item{"alpha", "alpha", ""},
item{"alpha.beta", "beta", "alpha", nil}, item{"alpha.beta", "beta", "alpha"},
item{"alpha.beta.gamma", "gamma", "alpha.beta", nil}, item{"alpha.beta.gamma", "gamma", "alpha.beta"},
item{"alpha.beta.gamma.delta", "delta", "alpha.beta.gamma", nil}, item{"alpha.beta.gamma.delta", "delta", "alpha.beta.gamma"},
item{"alpha.beta.gamma.delta.", "delta", "alpha.beta.gamma", nil}, item{"alpha.beta.gamma.delta.", "delta", "alpha.beta.gamma"},
} }
func TestSplitDomainHead(t *testing.T) { func TestSplitDomainHead(t *testing.T) {
for i := range items { for i := range items {
head, rest, err := util.SplitDomainHead(items[i].input) head, rest := util.SplitDomainHead(items[i].input)
if head != items[i].expectedHead { if head != items[i].expectedHead {
t.Errorf("Input \"%s\": head \"%s\" does not equal expected value \"%s\"", items[i].input, head, items[i].expectedHead) t.Errorf("Input \"%s\": head \"%s\" does not equal expected value \"%s\"", items[i].input, head, items[i].expectedHead)
} }
if rest != items[i].expectedRest { if rest != items[i].expectedRest {
t.Errorf("Input \"%s\": rest \"%s\" does not equal expected value \"%s\"", items[i].input, rest, items[i].expectedRest) t.Errorf("Input \"%s\": rest \"%s\" does not equal expected value \"%s\"", items[i].input, rest, items[i].expectedRest)
} }
if err != items[i].expectedError {
t.Errorf("Input \"%s\": error \"%s\" does not equal expected value \"%s\"", items[i].input, err, items[i].expectedError)
}
} }
} }

Loading…
Cancel
Save