forked from emmaly/go-pkg-rss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed_test.go
78 lines (64 loc) · 2.12 KB
/
feed_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
package feeder
import (
"testing"
"io/ioutil"
)
var items []*Item
func TestFeed(t *testing.T) {
urilist := []string{
//"http://cyber.law.harvard.edu/rss/examples/sampleRss091.xml", // Non-utf8 encoding.
"http://store.steampowered.com/feeds/news.xml", // This feed violates the rss spec.
"http://cyber.law.harvard.edu/rss/examples/sampleRss092.xml",
"http://cyber.law.harvard.edu/rss/examples/rss2sample.xml",
"http://blog.case.edu/news/feed.atom",
}
var feed *Feed
var err error
for _, uri := range urilist {
feed = New(5, true, chanHandler, itemHandler)
if err = feed.Fetch(uri, nil); err != nil {
t.Errorf("%s >>> %s", uri, err)
return
}
}
}
func Test_AtomAuthor(t *testing.T) {
content, err := ioutil.ReadFile("testdata/idownload.atom")
if err != nil {
t.Errorf("unable to load file")
}
feed := New(1, true, chanHandler, itemHandler)
err = feed.FetchBytes("http://example.com", content, nil)
item := items[0]
expected := "Cody Lee"
if item.Author.Name != expected {
t.Errorf("Expected author to be %s but found %s", expected, item.Author.Name)
}
}
func Test_RssAuthor(t *testing.T) {
content, _ := ioutil.ReadFile("testdata/boing.rss")
feed := New(1, true, chanHandler, itemHandler)
feed.FetchBytes("http://example.com", content, nil)
item := items[0]
expected := "Cory Doctorow"
if item.Author.Name != expected {
t.Errorf("Expected author to be %s but found %s", expected, item.Author.Name)
}
}
func Test_CData(t *testing.T) {
content, _ := ioutil.ReadFile("testdata/iosBoardGameGeek.rss")
feed := New(1, true, chanHandler, itemHandler)
feed.FetchBytes("http://example.com", content, nil)
item := items[0]
expected := `<p>abc<div>"def"</div>ghi`
if item.Description != expected {
t.Errorf("Expected item.Description to be [%s] but item.Description=[%s]", expected, item.Description)
}
}
func chanHandler(feed *Feed, newchannels []*Channel) {
println(len(newchannels), "new channel(s) in", feed.Url)
}
func itemHandler(feed *Feed, ch *Channel, newitems []*Item) {
items = newitems
println(len(newitems), "new item(s) in", ch.Title, "of", feed.Url)
}