-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_test.go
39 lines (33 loc) · 912 Bytes
/
util_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package crawler
import (
"testing"
)
func TestShortArrayReturnsEmptyArrayWithDesiredSmallCap(t *testing.T) {
arr := shortArray[int]()
expectEqualInTest(t, len(arr), 0)
expectEqualInTest(t, cap(arr), 10)
}
func TestGetHostOfUrl(t *testing.T) {
host, err := getHost("https://www.example.com/some/path?query=123")
if err != nil {
t.Fatal(err)
}
expectEqualInTest(t, host, "www.example.com")
host, err = getHost("https://example.com/a")
if err != nil {
t.Fatal(err)
}
expectEqualInTest(t, host, "example.com")
}
func TestSameHost(t *testing.T) {
is_same_domain, err := isSameHost("https://www.example.com", "https://www.example.com/a/b/c")
if err != nil {
t.Fatal(err)
}
expectEqualInTest(t, is_same_domain, true)
is_same_domain, err = isSameHost("http://www.example.com", "http://www.another.com/a/b/c")
if err != nil {
t.Fatal(err)
}
expectEqualInTest(t, is_same_domain, false)
}