2009-11-23 12:46:12 +00:00
|
|
|
package feeder
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestFeed(t *testing.T) {
|
|
|
|
urilist := []string{
|
2012-02-29 10:31:01 +00:00
|
|
|
//"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.
|
2009-11-23 12:46:12 +00:00
|
|
|
"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",
|
2010-05-23 14:21:30 +00:00
|
|
|
}
|
2009-11-23 12:46:12 +00:00
|
|
|
|
2010-05-25 23:41:44 +00:00
|
|
|
var feed *Feed
|
2011-11-02 15:51:04 +00:00
|
|
|
var err error
|
2010-05-25 23:41:44 +00:00
|
|
|
|
2009-11-23 12:46:12 +00:00
|
|
|
for _, uri := range urilist {
|
2010-12-17 23:25:16 +00:00
|
|
|
feed = New(5, true, chanHandler, itemHandler)
|
2010-05-25 23:41:44 +00:00
|
|
|
|
2012-02-29 10:31:01 +00:00
|
|
|
if err = feed.Fetch(uri, nil); err != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
t.Errorf("%s >>> %s", uri, err)
|
2011-02-01 14:30:39 +00:00
|
|
|
return
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-17 23:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func chanHandler(feed *Feed, newchannels []*Channel) {
|
2011-02-01 14:30:39 +00:00
|
|
|
println(len(newchannels), "new channel(s) in", feed.Url)
|
2010-12-17 23:25:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func itemHandler(feed *Feed, ch *Channel, newitems []*Item) {
|
2011-02-01 14:30:39 +00:00
|
|
|
println(len(newitems), "new item(s) in", ch.Title, "of", feed.Url)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|