2020-01-25 17:43:02 +00:00
|
|
|
package resolver
|
2015-02-03 14:53:57 +00:00
|
|
|
|
|
|
|
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() {
|
2021-04-15 05:04:58 +00:00
|
|
|
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"})
|
2015-02-03 14:53:57 +00:00
|
|
|
|
|
|
|
v, found := root.search(strings.Split("google.com", "."))
|
|
|
|
So(found, ShouldEqual, false)
|
|
|
|
|
|
|
|
v, found = root.search(strings.Split("baidu.cn", "."))
|
|
|
|
So(found, ShouldEqual, true)
|
2021-04-15 05:04:58 +00:00
|
|
|
So(v.address, ShouldEqual, "166.111.8.28")
|
2015-02-03 14:53:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Google should be found", t, func() {
|
2021-04-15 05:04:58 +00:00
|
|
|
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"})
|
2015-02-03 14:53:57 +00:00
|
|
|
|
|
|
|
v, found := root.search(strings.Split("google.com", "."))
|
|
|
|
So(found, ShouldEqual, true)
|
2021-04-15 05:04:58 +00:00
|
|
|
So(v.address, ShouldEqual, "8.8.8.8")
|
2015-02-03 14:53:57 +00:00
|
|
|
|
2018-02-01 10:39:40 +00:00
|
|
|
v, found = root.search(strings.Split("www.google.com", "."))
|
|
|
|
So(found, ShouldEqual, true)
|
2021-04-15 05:04:58 +00:00
|
|
|
So(v.address, ShouldEqual, "8.8.8.8")
|
2018-02-01 10:39:40 +00:00
|
|
|
|
2015-02-03 14:53:57 +00:00
|
|
|
v, found = root.search(strings.Split("scholar.google.com", "."))
|
|
|
|
So(found, ShouldEqual, true)
|
2021-04-15 05:04:58 +00:00
|
|
|
So(v.address, ShouldEqual, "208.67.222.222")
|
2015-02-03 14:53:57 +00:00
|
|
|
|
|
|
|
v, found = root.search(strings.Split("twitter.com", "."))
|
|
|
|
So(found, ShouldEqual, true)
|
2021-04-15 05:04:58 +00:00
|
|
|
So(v.address, ShouldEqual, "8.8.8.8")
|
2015-02-03 14:53:57 +00:00
|
|
|
|
|
|
|
v, found = root.search(strings.Split("baidu.cn", "."))
|
|
|
|
So(found, ShouldEqual, true)
|
2021-04-15 05:04:58 +00:00
|
|
|
So(v.address, ShouldEqual, "166.111.8.28")
|
2015-02-03 14:53:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|