package resolver import ( "strings" "testing" . "github.com/smartystreets/goconvey/convey" ) func Test_Suffix_Tree(t *testing.T) { root := newSuffixTreeRoot() Convey("Google should not be found", t, func() { root.insert("cn", &Nameserver{address: "114.114.114.114"}) root.sinsert([]string{"baidu", "cn"}, &Nameserver{address: "166.111.8.28"}) root.sinsert([]string{"sina", "cn"}, &Nameserver{address: "114.114.114.114"}) v, found := root.search(strings.Split("google.com", ".")) So(found, ShouldEqual, false) v, found = root.search(strings.Split("baidu.cn", ".")) So(found, ShouldEqual, true) So(v.address, ShouldEqual, "166.111.8.28") }) Convey("Google should be found", t, func() { root.sinsert(strings.Split("com", "."), &Nameserver{address: ""}) root.sinsert(strings.Split("google.com", "."), &Nameserver{address: "8.8.8.8"}) root.sinsert(strings.Split("twitter.com", "."), &Nameserver{address: "8.8.8.8"}) root.sinsert(strings.Split("scholar.google.com", "."), &Nameserver{address: "208.67.222.222"}) v, found := root.search(strings.Split("google.com", ".")) So(found, ShouldEqual, true) So(v.address, ShouldEqual, "8.8.8.8") v, found = root.search(strings.Split("www.google.com", ".")) So(found, ShouldEqual, true) So(v.address, ShouldEqual, "8.8.8.8") v, found = root.search(strings.Split("scholar.google.com", ".")) So(found, ShouldEqual, true) So(v.address, ShouldEqual, "208.67.222.222") v, found = root.search(strings.Split("twitter.com", ".")) So(found, ShouldEqual, true) So(v.address, ShouldEqual, "8.8.8.8") v, found = root.search(strings.Split("baidu.cn", ".")) So(found, ShouldEqual, true) So(v.address, ShouldEqual, "166.111.8.28") }) }