From c67fc3a2a15e55127da8becdf37d8b463f99196a Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Thu, 12 Sep 2013 09:18:54 +0100 Subject: [PATCH] Add more tests for the labels --- labels.go | 1 - labels_test.go | 25 +++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/labels.go b/labels.go index 58e3bed5..57d55853 100644 --- a/labels.go +++ b/labels.go @@ -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 { diff --git a/labels_test.go b/labels_test.go index 38d913c3..1945fa64 100644 --- a/labels_test.go +++ b/labels_test.go @@ -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)