-
Notifications
You must be signed in to change notification settings - Fork 0
/
html_parser_test.go
47 lines (40 loc) · 1.18 KB
/
html_parser_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
package bslc
import (
"bytes"
"testing"
"net/http"
"net/url"
"time"
)
func TestParseHTML(t *testing.T) {
html := `<html>
<body>
<a href="http://1.2.3.4/1">link</a>
<img src="http://2.3.4.5/image">
</body>
</html>`
container := NewLocalURLContainer(NewIPNetContainer([]string{"0.0.0.0/0"}), []string{})
buf := bytes.NewBuffer([]byte(html))
body := mockBody{ readFunc: func(p []byte) (int, error) {
return buf.Read(p)
}}
theUrl, _ := url.Parse("http://localhost/index.html")
header := http.Header{}
header.Set("Content-Type", "text/html; charset=utf-8")
res := http.Response{
Status: "OK",
Header: header,
Request: &http.Request{ URL: theUrl },
Body: body,
}
content := newContent(&res, make(chan bool))
content.readBody()
parseHTML(content, container)
<-time.After(time.Millisecond)
if u, _ := container.NextURL(); u != "http://1.2.3.4/1" {
t.Error("Invalid url received")
}
if u, _ := container.NextURL(); u != "http://2.3.4.5/image" {
t.Error("Invalid url received")
}
}