-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser_test.go
40 lines (37 loc) · 745 Bytes
/
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
package youcrawl
import (
"errors"
"github.com/PuerkitoBio/goquery"
"testing"
)
func TestParser(t *testing.T) {
task := &Task{
Url: "http://www.example.com",
Context: Context{},
}
reader, err := RequestWithURL(task)
if err != nil {
t.Error(err)
}
doc, err := goquery.NewDocumentFromReader(reader)
if err != nil {
EngineLogger.Error(err)
}
task.Context.Doc = doc
err = ParseHTML(DefaultTestParser, &task.Context)
if err != nil {
t.Error(err)
}
}
func TestParserOnError(t *testing.T) {
task := &Task{
Url: "https://api.github.com/",
Context: Context{},
}
err := ParseHTML(func(ctx *Context) error {
return errors.New("test error")
}, &task.Context)
if err == nil {
t.Error("must cause error")
}
}