From 8c53fb827b1e5cc9463856bc15d28f512b5dffe9 Mon Sep 17 00:00:00 2001 From: Max Redmond Date: Wed, 31 Oct 2018 18:53:14 -0400 Subject: [PATCH] adding a test for rss consumption --- consume_test.go | 198 ++++++++++++++++++++++++++++++++++++++++++++++++ test.rss | 96 +++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 consume_test.go create mode 100644 test.rss diff --git a/consume_test.go b/consume_test.go new file mode 100644 index 0000000..4dd771a --- /dev/null +++ b/consume_test.go @@ -0,0 +1,198 @@ +package feeds + +import ( + "encoding/xml" + "io/ioutil" + "os" + "reflect" + "testing" + + "github.com/kr/pretty" +) + +var testRssFeedXML = RssFeedXml{ + XMLName: xml.Name{Space: "", Local: "rss"}, + Version: "2.0", + ContentNamespace: "", + Channel: &RssFeed{ + XMLName: xml.Name{Space: "", Local: "channel"}, + Title: "Lorem ipsum feed for an interval of 1 minutes", + Link: "http://example.com/", + Description: "This is a constantly updating lorem ipsum feed", + Language: "", + Copyright: "Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.", + ManagingEditor: "", + WebMaster: "", + PubDate: "Tue, 30 Oct 2018 23:22:00 GMT", + LastBuildDate: "Tue, 30 Oct 2018 23:22:37 GMT", + Category: "", + Generator: "RSS for Node", + Docs: "", + Cloud: "", + Ttl: 60, + Rating: "", + SkipHours: "", + SkipDays: "", + Image: (*RssImage)(nil), + TextInput: (*RssTextInput)(nil), + Items: []*RssItem{ + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:22:00+00:00", + Link: "http://example.com/test/1540941720", + Description: "Exercitation ut Lorem sint proident.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941720", + PubDate: "Tue, 30 Oct 2018 23:22:00 GMT", + Source: "", + }, + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:21:00+00:00", + Link: "http://example.com/test/1540941660", + Description: "Ea est do quis fugiat exercitation.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941660", + PubDate: "Tue, 30 Oct 2018 23:21:00 GMT", + Source: "", + }, + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:20:00+00:00", + Link: "http://example.com/test/1540941600", + Description: "Ipsum velit cillum ad laborum sit nulla exercitation consequat sint veniam culpa veniam voluptate incididunt.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941600", + PubDate: "Tue, 30 Oct 2018 23:20:00 GMT", + Source: "", + }, + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:19:00+00:00", + Link: "http://example.com/test/1540941540", + Description: "Ullamco pariatur aliqua consequat ea veniam id qui incididunt laborum.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941540", + PubDate: "Tue, 30 Oct 2018 23:19:00 GMT", + Source: "", + }, + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:18:00+00:00", + Link: "http://example.com/test/1540941480", + Description: "Velit proident aliquip aliquip anim mollit voluptate laboris voluptate et occaecat occaecat laboris ea nulla.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941480", + PubDate: "Tue, 30 Oct 2018 23:18:00 GMT", + Source: "", + }, + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:17:00+00:00", + Link: "http://example.com/test/1540941420", + Description: "Do in quis mollit consequat id in minim laborum sint exercitation laborum elit officia.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941420", + PubDate: "Tue, 30 Oct 2018 23:17:00 GMT", + Source: "", + }, + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:16:00+00:00", + Link: "http://example.com/test/1540941360", + Description: "Irure id sint ullamco Lorem magna consectetur officia adipisicing duis incididunt.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941360", + PubDate: "Tue, 30 Oct 2018 23:16:00 GMT", + Source: "", + }, + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:15:00+00:00", + Link: "http://example.com/test/1540941300", + Description: "Sunt anim excepteur esse nisi commodo culpa laborum exercitation ad anim ex elit.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941300", + PubDate: "Tue, 30 Oct 2018 23:15:00 GMT", + Source: "", + }, + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:14:00+00:00", + Link: "http://example.com/test/1540941240", + Description: "Excepteur aliquip fugiat ex labore nisi.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941240", + PubDate: "Tue, 30 Oct 2018 23:14:00 GMT", + Source: "", + }, + &RssItem{ + XMLName: xml.Name{Space: "", Local: "item"}, + Title: "Lorem ipsum 2018-10-30T23:13:00+00:00", + Link: "http://example.com/test/1540941180", + Description: "Id proident adipisicing proident pariatur aute pariatur pariatur dolor dolor in voluptate dolor.", + Content: (*RssContent)(nil), + Author: "", + Category: "", + Comments: "", + Enclosure: (*RssEnclosure)(nil), + Guid: "http://example.com/test/1540941180", + PubDate: "Tue, 30 Oct 2018 23:13:00 GMT", + Source: "", + }, + }, + }, +} + +func TestRssUnmarshal(t *testing.T) { + var xmlFeed RssFeedXml + xmlFile, err := os.Open("test.rss") + if err != nil { + panic("AHH file bad") + } + bytes, _ := ioutil.ReadAll(xmlFile) + xml.Unmarshal(bytes, &xmlFeed) + + if !reflect.DeepEqual(testRssFeedXML, xmlFeed) { + diffs := pretty.Diff(testRssFeedXML, xmlFeed) + t.Log(pretty.Println(diffs)) + t.Error("object was not unmarshalled correctly") + } + +} diff --git a/test.rss b/test.rss new file mode 100644 index 0000000..8d912ab --- /dev/null +++ b/test.rss @@ -0,0 +1,96 @@ + + + + <![CDATA[Lorem ipsum feed for an interval of 1 minutes]]> + + http://example.com/ + RSS for Node + Tue, 30 Oct 2018 23:22:37 GMT + + Tue, 30 Oct 2018 23:22:00 GMT + + 60 + + <![CDATA[Lorem ipsum 2018-10-30T23:22:00+00:00]]> + + http://example.com/test/1540941720 + http://example.com/test/1540941720 + + Tue, 30 Oct 2018 23:22:00 GMT + + + <![CDATA[Lorem ipsum 2018-10-30T23:21:00+00:00]]> + + http://example.com/test/1540941660 + http://example.com/test/1540941660 + + Tue, 30 Oct 2018 23:21:00 GMT + + + <![CDATA[Lorem ipsum 2018-10-30T23:20:00+00:00]]> + + http://example.com/test/1540941600 + http://example.com/test/1540941600 + + Tue, 30 Oct 2018 23:20:00 GMT + + + <![CDATA[Lorem ipsum 2018-10-30T23:19:00+00:00]]> + + http://example.com/test/1540941540 + http://example.com/test/1540941540 + + Tue, 30 Oct 2018 23:19:00 GMT + + + <![CDATA[Lorem ipsum 2018-10-30T23:18:00+00:00]]> + + http://example.com/test/1540941480 + http://example.com/test/1540941480 + + Tue, 30 Oct 2018 23:18:00 GMT + + + <![CDATA[Lorem ipsum 2018-10-30T23:17:00+00:00]]> + + http://example.com/test/1540941420 + http://example.com/test/1540941420 + + Tue, 30 Oct 2018 23:17:00 GMT + + + <![CDATA[Lorem ipsum 2018-10-30T23:16:00+00:00]]> + + http://example.com/test/1540941360 + http://example.com/test/1540941360 + + Tue, 30 Oct 2018 23:16:00 GMT + + + <![CDATA[Lorem ipsum 2018-10-30T23:15:00+00:00]]> + + http://example.com/test/1540941300 + http://example.com/test/1540941300 + + Tue, 30 Oct 2018 23:15:00 GMT + + + <![CDATA[Lorem ipsum 2018-10-30T23:14:00+00:00]]> + + http://example.com/test/1540941240 + http://example.com/test/1540941240 + + Tue, 30 Oct 2018 23:14:00 GMT + + + <![CDATA[Lorem ipsum 2018-10-30T23:13:00+00:00]]> + + http://example.com/test/1540941180 + http://example.com/test/1540941180 + + Tue, 30 Oct 2018 23:13:00 GMT + + + \ No newline at end of file