Add more tests for the labels

This commit is contained in:
Miek Gieben 2013-09-12 09:18:54 +01:00
parent 9764818db3
commit c67fc3a2a1
2 changed files with 21 additions and 5 deletions

View File

@ -89,7 +89,6 @@ func CountLabel(s string) (labels int) {
if s == "." {
return
}
// s = Fqdn(s) // TODO(miek): annoyed I need this
off := 0
end := false
for {

View File

@ -14,6 +14,7 @@ func TestCompareDomainName(t *testing.T) {
s3 := "www.bla.nl."
s4 := "nl.www.bla."
s5 := "nl"
s6 := "miek.nl"
if CompareDomainName(s1, s2) != 2 {
t.Logf("%s with %s should be %d", s1, s2, 2)
@ -27,10 +28,16 @@ func TestCompareDomainName(t *testing.T) {
t.Logf("%s with %s should be %d", s3, s4, 0)
t.Fail()
}
// Non qualified tests
if CompareDomainName(s1, s5) != 1 {
t.Logf("%s with %s should be %d", s1, s5, 1)
t.Fail()
}
if CompareDomainName(s1, s6) != 2 {
t.Logf("%s with %s should be %d", s1, s5, 2)
t.Fail()
}
if CompareDomainName(s1, ".") != 0 {
t.Logf("%s with %s should be %d", s1, s5, 0)
t.Fail()
@ -68,12 +75,21 @@ func TestSplit2(t *testing.T) {
splitter := map[string][]int{
"www.miek.nl.": []int{0, 4, 9},
"www.miek.nl": []int{0, 4, 9},
"nl": []int{0},
}
for s, i := range splitter {
x := Split(s)
if x[0] != i[0] || x[1] != i[1] || x[2] != i[2] {
t.Logf("Labels should be %v, got %v: %s\n", i, x, s)
t.Fail()
switch len(i) {
case 1:
if x[0] != i[0] {
t.Logf("Labels should be %v, got %v: %s\n", i, x, s)
t.Fail()
}
default:
if x[0] != i[0] || x[1] != i[1] || x[2] != i[2] {
t.Logf("Labels should be %v, got %v: %s\n", i, x, s)
t.Fail()
}
}
}
}
@ -82,7 +98,8 @@ func TestCountLabel(t *testing.T) {
splitter := map[string]int{
"www.miek.nl.": 3,
"www.miek.nl": 3,
".": 0,
"nl": 1,
".": 0,
}
for s, i := range splitter {
x := CountLabel(s)