2009-11-23 12:46:12 +00:00
|
|
|
package feeder
|
|
|
|
|
|
|
|
import "testing"
|
2010-12-17 20:57:48 +00:00
|
|
|
import "os"
|
2009-11-23 12:46:12 +00:00
|
|
|
|
|
|
|
func TestFeed(t *testing.T) {
|
|
|
|
urilist := []string{
|
|
|
|
"http://cyber.law.harvard.edu/rss/examples/sampleRss091.xml",
|
|
|
|
"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
|
|
|
|
var err os.Error
|
|
|
|
|
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
|
|
|
|
|
|
|
if err = feed.Fetch(uri); err != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
t.Errorf("%s >>> %s", uri, err)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-17 23:25:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Output of handlers:
|
|
|
|
|
|
|
|
6 new item(s) in WriteTheWeb of http://cyber.law.harvard.edu/rss/examples/sampleRss091.xml
|
|
|
|
1 new channel(s) in http://cyber.law.harvard.edu/rss/examples/sampleRss091.xml
|
|
|
|
21 new item(s) in Dave Winer: Grateful Dead of http://cyber.law.harvard.edu/rss/examples/sampleRss092.xml
|
|
|
|
1 new channel(s) in http://cyber.law.harvard.edu/rss/examples/sampleRss092.xml
|
|
|
|
4 new item(s) in Liftoff News of http://cyber.law.harvard.edu/rss/examples/rss2sample.xml
|
|
|
|
1 new channel(s) in http://cyber.law.harvard.edu/rss/examples/rss2sample.xml
|
|
|
|
15 new item(s) in Blog@Case of http://blog.case.edu/news/feed.atom
|
|
|
|
1 new channel(s) in http://blog.case.edu/news/feed.atom
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
func chanHandler(feed *Feed, newchannels []*Channel) {
|
|
|
|
//println(len(newchannels), "new channel(s) in", feed.Url)
|
|
|
|
}
|
|
|
|
|
|
|
|
func itemHandler(feed *Feed, ch *Channel, newitems []*Item) {
|
|
|
|
//println(len(newitems), "new item(s) in", ch.Title, "of", feed.Url)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|