forked from hakluke/hakrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
88 lines (83 loc) · 2.02 KB
/
main_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
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"bytes"
"os"
"strings"
"testing"
"gopkg.in/h2non/gock.v1"
)
func Test_main(t *testing.T) {
defer gock.Off()
gock.New("http://example.com").
Get("/").
Persist().
Reply(200).
SetHeader("Content-Type", "text/html").
BodyString(`
<a href="http://example.com/link"></a>
<a href="http://www.example.com/link"></a>
<a href="http://sub.example.com/link"></a>
<a href="http://another-example.com/link"></a>
`)
tests := []struct {
name string
args []string
output []string
}{
{
name: "normal scope (subs)",
args: []string{"hakrawler", "-url", "http://example.com", "-plain"},
output: []string{
"http://example.com/link",
// "example.com", // TODO: this url should show up -- fix this bug.
"http://www.example.com/link",
"www.example.com",
"http://sub.example.com/link",
"sub.example.com",
},
},
{
name: "scope strict",
args: []string{"hakrawler", "-url", "http://example.com", "-plain", "-scope", "strict"},
output: []string{
"http://example.com/link",
"example.com",
},
},
{
name: "scope www",
args: []string{"hakrawler", "-url", "http://example.com", "-plain", "-scope", "www"},
output: []string{
"http://example.com/link",
"example.com",
"http://www.example.com/link",
"www.example.com",
},
},
{
name: "scope yolo",
args: []string{"hakrawler", "-url", "http://example.com", "-plain", "-scope", "yolo"},
output: []string{
"http://example.com/link",
"example.com",
"http://www.example.com/link",
"www.example.com",
"http://sub.example.com/link",
"sub.example.com",
"http://another-example.com/link",
"another-example.com",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
os.Args = tt.args
out = bytes.NewBuffer(nil)
main()
output := strings.Join(tt.output[:], "\n")
if actual := strings.TrimRight(out.(*bytes.Buffer).String(), "\n"); actual != output {
t.Fatalf("expected <%s>, but got <%s>", output, actual)
}
})
}
}