-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_test.go
75 lines (59 loc) · 1.73 KB
/
helper_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"testing"
)
func TestTask(t *testing.T) {
task := &Task{
Uri: "/subdir/name-of-uri",
Site: &Site{
BaseUrl: "http://domain.com",
MaxDepth: 3,
KeywordPrefix: "/db",
},
Depth: 0,
}
expectUrl := "http://domain.com/subdir/name-of-uri"
gotUrl := task.GetUrl()
if gotUrl != expectUrl {
t.Errorf("Test Task.GetUrl failed. Got %q, expected %q", gotUrl, expectUrl)
}
expectedSubdirTree := "n/a/m"
gotSubdirTree := task.GetSubTree()
if gotSubdirTree != expectedSubdirTree {
t.Errorf("Test Task.GetSubdirTree() failed. Got %q, expected %q", gotSubdirTree, expectedSubdirTree)
}
expectedFilename := "__subdir__name-of-uri"
gotFilename := task.GetFilename()
if gotFilename != expectedFilename {
t.Errorf("Test Task.GetFilename() failed. Got %q, expected %q", gotFilename, expectedFilename)
}
}
func TestTaskSubdirs(t *testing.T) {
task := &Task{
Uri: "/subdir/name-of-uri",
Site: &Site{
BaseUrl: "http://domain.com",
MaxDepth: 3,
KeywordPrefix: "/db",
},
Depth: 0,
}
task.Uri = "/a"
expectedSubdirTree := "a/0/0"
gotSubdirTree := task.GetSubTree()
if gotSubdirTree != expectedSubdirTree {
t.Errorf("Test Task.GetSubdirTree() failed. Got %q, expected %q", gotSubdirTree, expectedSubdirTree)
}
task.Uri = "/ab"
expectedSubdirTree = "a/b/0"
gotSubdirTree = task.GetSubTree()
if gotSubdirTree != expectedSubdirTree {
t.Errorf("Test Task.GetSubdirTree() failed. Got %q, expected %q", gotSubdirTree, expectedSubdirTree)
}
task.Uri = "/abc"
expectedSubdirTree = "a/b/c"
gotSubdirTree = task.GetSubTree()
if gotSubdirTree != expectedSubdirTree {
t.Errorf("Test Task.GetSubdirTree() failed. Got %q, expected %q", gotSubdirTree, expectedSubdirTree)
}
}