mirror of https://github.com/gorilla/feeds
Max Redmond
6 years ago
committed by
Kamil Kisiel
2 changed files with 294 additions and 0 deletions
@ -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") |
||||
} |
||||
|
||||
} |
@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" |
||||
xmlns:content="http://purl.org/rss/1.0/modules/content/" |
||||
xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"> |
||||
<channel> |
||||
<title><![CDATA[Lorem ipsum feed for an interval of 1 minutes]]></title> |
||||
<description><![CDATA[This is a constantly updating lorem ipsum feed]]></description> |
||||
<link>http://example.com/</link> |
||||
<generator>RSS for Node</generator> |
||||
<lastBuildDate>Tue, 30 Oct 2018 23:22:37 GMT</lastBuildDate> |
||||
<author><![CDATA[John Smith]]></author> |
||||
<pubDate>Tue, 30 Oct 2018 23:22:00 GMT</pubDate> |
||||
<copyright><![CDATA[Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.]]></copyright> |
||||
<ttl>60</ttl> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:22:00+00:00]]></title> |
||||
<description><![CDATA[Exercitation ut Lorem sint proident.]]></description> |
||||
<link>http://example.com/test/1540941720</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941720</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:22:00 GMT</pubDate> |
||||
</item> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:21:00+00:00]]></title> |
||||
<description><![CDATA[Ea est do quis fugiat exercitation.]]></description> |
||||
<link>http://example.com/test/1540941660</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941660</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:21:00 GMT</pubDate> |
||||
</item> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:20:00+00:00]]></title> |
||||
<description><![CDATA[Ipsum velit cillum ad laborum sit nulla exercitation consequat sint veniam culpa veniam voluptate incididunt.]]></description> |
||||
<link>http://example.com/test/1540941600</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941600</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:20:00 GMT</pubDate> |
||||
</item> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:19:00+00:00]]></title> |
||||
<description><![CDATA[Ullamco pariatur aliqua consequat ea veniam id qui incididunt laborum.]]></description> |
||||
<link>http://example.com/test/1540941540</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941540</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:19:00 GMT</pubDate> |
||||
</item> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:18:00+00:00]]></title> |
||||
<description><![CDATA[Velit proident aliquip aliquip anim mollit voluptate laboris voluptate et occaecat occaecat laboris ea nulla.]]></description> |
||||
<link>http://example.com/test/1540941480</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941480</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:18:00 GMT</pubDate> |
||||
</item> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:17:00+00:00]]></title> |
||||
<description><![CDATA[Do in quis mollit consequat id in minim laborum sint exercitation laborum elit officia.]]></description> |
||||
<link>http://example.com/test/1540941420</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941420</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:17:00 GMT</pubDate> |
||||
</item> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:16:00+00:00]]></title> |
||||
<description><![CDATA[Irure id sint ullamco Lorem magna consectetur officia adipisicing duis incididunt.]]></description> |
||||
<link>http://example.com/test/1540941360</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941360</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:16:00 GMT</pubDate> |
||||
</item> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:15:00+00:00]]></title> |
||||
<description><![CDATA[Sunt anim excepteur esse nisi commodo culpa laborum exercitation ad anim ex elit.]]></description> |
||||
<link>http://example.com/test/1540941300</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941300</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:15:00 GMT</pubDate> |
||||
</item> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:14:00+00:00]]></title> |
||||
<description><![CDATA[Excepteur aliquip fugiat ex labore nisi.]]></description> |
||||
<link>http://example.com/test/1540941240</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941240</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:14:00 GMT</pubDate> |
||||
</item> |
||||
<item> |
||||
<title><![CDATA[Lorem ipsum 2018-10-30T23:13:00+00:00]]></title> |
||||
<description><![CDATA[Id proident adipisicing proident pariatur aute pariatur pariatur dolor dolor in voluptate dolor.]]></description> |
||||
<link>http://example.com/test/1540941180</link> |
||||
<guid isPermaLink="true">http://example.com/test/1540941180</guid> |
||||
<dc:creator><![CDATA[John Smith]]></dc:creator> |
||||
<pubDate>Tue, 30 Oct 2018 23:13:00 GMT</pubDate> |
||||
</item> |
||||
</channel> |
||||
</rss> |
Loading…
Reference in new issue