Skip to content

Commit 9dd2db1

Browse files
Athuluskisielk
authored andcommitted
adding a test for atom feeds as well
1 parent 8c53fb8 commit 9dd2db1

File tree

2 files changed

+295
-0
lines changed

2 files changed

+295
-0
lines changed

consume_test.go

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,193 @@ var testRssFeedXML = RssFeedXml{
180180
},
181181
}
182182

183+
var testAtomFeedXML = AtomFeed{
184+
XMLName: xml.Name{Space: "", Local: "feed"},
185+
Xmlns: "",
186+
Title: "Lorem ipsum feed for an interval of 1 minutes",
187+
Id: "",
188+
Updated: "",
189+
Category: "",
190+
Icon: "",
191+
Logo: "",
192+
Rights: "",
193+
Subtitle: "",
194+
Link: &AtomLink{
195+
XMLName: xml.Name{Space: "", Local: "link"},
196+
Href: "",
197+
Rel: "",
198+
Type: "",
199+
Length: "",
200+
},
201+
Author: &AtomAuthor{
202+
XMLName: xml.Name{Space: "", Local: "author"},
203+
AtomPerson: AtomPerson{},
204+
},
205+
Contributor: (*AtomContributor)(nil),
206+
Entries: []*AtomEntry{
207+
&AtomEntry{
208+
XMLName: xml.Name{Space: "", Local: "entry"},
209+
Xmlns: "",
210+
Title: "Lorem ipsum 2018-10-30T23:22:00+00:00",
211+
Updated: "",
212+
Id: "",
213+
Category: "",
214+
Content: (*AtomContent)(nil),
215+
Rights: "",
216+
Source: "",
217+
Published: "",
218+
Contributor: (*AtomContributor)(nil),
219+
Links: nil,
220+
Summary: (*AtomSummary)(nil),
221+
Author: (*AtomAuthor)(nil),
222+
},
223+
&AtomEntry{
224+
XMLName: xml.Name{Space: "", Local: "entry"},
225+
Xmlns: "",
226+
Title: "Lorem ipsum 2018-10-30T23:21:00+00:00",
227+
Updated: "",
228+
Id: "",
229+
Category: "",
230+
Content: (*AtomContent)(nil),
231+
Rights: "",
232+
Source: "",
233+
Published: "",
234+
Contributor: (*AtomContributor)(nil),
235+
Links: nil,
236+
Summary: (*AtomSummary)(nil),
237+
Author: (*AtomAuthor)(nil),
238+
},
239+
&AtomEntry{
240+
XMLName: xml.Name{Space: "", Local: "entry"},
241+
Xmlns: "",
242+
Title: "Lorem ipsum 2018-10-30T23:20:00+00:00",
243+
Updated: "",
244+
Id: "",
245+
Category: "",
246+
Content: (*AtomContent)(nil),
247+
Rights: "",
248+
Source: "",
249+
Published: "",
250+
Contributor: (*AtomContributor)(nil),
251+
Links: nil,
252+
Summary: (*AtomSummary)(nil),
253+
Author: (*AtomAuthor)(nil),
254+
},
255+
&AtomEntry{
256+
XMLName: xml.Name{Space: "", Local: "entry"},
257+
Xmlns: "",
258+
Title: "Lorem ipsum 2018-10-30T23:19:00+00:00",
259+
Updated: "",
260+
Id: "",
261+
Category: "",
262+
Content: (*AtomContent)(nil),
263+
Rights: "",
264+
Source: "",
265+
Published: "",
266+
Contributor: (*AtomContributor)(nil),
267+
Links: nil,
268+
Summary: (*AtomSummary)(nil),
269+
Author: (*AtomAuthor)(nil),
270+
},
271+
&AtomEntry{
272+
XMLName: xml.Name{Space: "", Local: "entry"},
273+
Xmlns: "",
274+
Title: "Lorem ipsum 2018-10-30T23:18:00+00:00",
275+
Updated: "",
276+
Id: "",
277+
Category: "",
278+
Content: (*AtomContent)(nil),
279+
Rights: "",
280+
Source: "",
281+
Published: "",
282+
Contributor: (*AtomContributor)(nil),
283+
Links: nil,
284+
Summary: (*AtomSummary)(nil),
285+
Author: (*AtomAuthor)(nil),
286+
},
287+
&AtomEntry{
288+
XMLName: xml.Name{Space: "", Local: "entry"},
289+
Xmlns: "",
290+
Title: "Lorem ipsum 2018-10-30T23:17:00+00:00",
291+
Updated: "",
292+
Id: "",
293+
Category: "",
294+
Content: (*AtomContent)(nil),
295+
Rights: "",
296+
Source: "",
297+
Published: "",
298+
Contributor: (*AtomContributor)(nil),
299+
Links: nil,
300+
Summary: (*AtomSummary)(nil),
301+
Author: (*AtomAuthor)(nil),
302+
},
303+
&AtomEntry{
304+
XMLName: xml.Name{Space: "", Local: "entry"},
305+
Xmlns: "",
306+
Title: "Lorem ipsum 2018-10-30T23:16:00+00:00",
307+
Updated: "",
308+
Id: "",
309+
Category: "",
310+
Content: (*AtomContent)(nil),
311+
Rights: "",
312+
Source: "",
313+
Published: "",
314+
Contributor: (*AtomContributor)(nil),
315+
Links: nil,
316+
Summary: (*AtomSummary)(nil),
317+
Author: (*AtomAuthor)(nil),
318+
},
319+
&AtomEntry{
320+
XMLName: xml.Name{Space: "", Local: "entry"},
321+
Xmlns: "",
322+
Title: "Lorem ipsum 2018-10-30T23:15:00+00:00",
323+
Updated: "",
324+
Id: "",
325+
Category: "",
326+
Content: (*AtomContent)(nil),
327+
Rights: "",
328+
Source: "",
329+
Published: "",
330+
Contributor: (*AtomContributor)(nil),
331+
Links: nil,
332+
Summary: (*AtomSummary)(nil),
333+
Author: (*AtomAuthor)(nil),
334+
},
335+
&AtomEntry{
336+
XMLName: xml.Name{Space: "", Local: "entry"},
337+
Xmlns: "",
338+
Title: "Lorem ipsum 2018-10-30T23:14:00+00:00",
339+
Updated: "",
340+
Id: "",
341+
Category: "",
342+
Content: (*AtomContent)(nil),
343+
Rights: "",
344+
Source: "",
345+
Published: "",
346+
Contributor: (*AtomContributor)(nil),
347+
Links: nil,
348+
Summary: (*AtomSummary)(nil),
349+
Author: (*AtomAuthor)(nil),
350+
},
351+
&AtomEntry{
352+
XMLName: xml.Name{Space: "", Local: "entry"},
353+
Xmlns: "",
354+
Title: "Lorem ipsum 2018-10-30T23:13:00+00:00",
355+
Updated: "",
356+
Id: "",
357+
Category: "",
358+
Content: (*AtomContent)(nil),
359+
Rights: "",
360+
Source: "",
361+
Published: "",
362+
Contributor: (*AtomContributor)(nil),
363+
Links: nil,
364+
Summary: (*AtomSummary)(nil),
365+
Author: (*AtomAuthor)(nil),
366+
},
367+
},
368+
}
369+
183370
func TestRssUnmarshal(t *testing.T) {
184371
var xmlFeed RssFeedXml
185372
xmlFile, err := os.Open("test.rss")
@@ -196,3 +383,19 @@ func TestRssUnmarshal(t *testing.T) {
196383
}
197384

198385
}
386+
387+
func TestAtomUnmarshal(t *testing.T) {
388+
var xmlFeed AtomFeed
389+
xmlFile, err := os.Open("test.atom")
390+
if err != nil {
391+
panic("AHH file bad")
392+
}
393+
bytes, _ := ioutil.ReadAll(xmlFile)
394+
xml.Unmarshal(bytes, &xmlFeed)
395+
396+
if !reflect.DeepEqual(testAtomFeedXML, xmlFeed) {
397+
diffs := pretty.Diff(testAtomFeedXML, xmlFeed)
398+
t.Log(pretty.Println(diffs))
399+
t.Error("object was not unmarshalled correctly")
400+
}
401+
}

test.atom

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<feed xmlns:atom="http://www.w3.org/2005/Atom">
3+
<title><![CDATA[Lorem ipsum feed for an interval of 1 minutes]]></title>
4+
<description><![CDATA[This is a constantly updating lorem ipsum feed]]></description>
5+
<link>http://example.com/</link>
6+
<generator>RSS for Node</generator>
7+
<lastBuildDate>Tue, 30 Oct 2018 23:22:37 GMT</lastBuildDate>
8+
<author><![CDATA[John Smith]]></author>
9+
<pubDate>Tue, 30 Oct 2018 23:22:00 GMT</pubDate>
10+
<copyright><![CDATA[Michael Bertolacci, licensed under a Creative Commons Attribution 3.0 Unported License.]]></copyright>
11+
<ttl>60</ttl>
12+
<entry>
13+
<title><![CDATA[Lorem ipsum 2018-10-30T23:22:00+00:00]]></title>
14+
<description><![CDATA[Exercitation ut Lorem sint proident.]]></description>
15+
<link>http://example.com/test/1540941720</link>
16+
<guid isPermaLink="true">http://example.com/test/1540941720</guid>
17+
<dc:creator><![CDATA[John Smith]]></dc:creator>
18+
<pubDate>Tue, 30 Oct 2018 23:22:00 GMT</pubDate>
19+
</entry>
20+
<entry>
21+
<title><![CDATA[Lorem ipsum 2018-10-30T23:21:00+00:00]]></title>
22+
<description><![CDATA[Ea est do quis fugiat exercitation.]]></description>
23+
<link>http://example.com/test/1540941660</link>
24+
<guid isPermaLink="true">http://example.com/test/1540941660</guid>
25+
<dc:creator><![CDATA[John Smith]]></dc:creator>
26+
<pubDate>Tue, 30 Oct 2018 23:21:00 GMT</pubDate>
27+
</entry>
28+
<entry>
29+
<title><![CDATA[Lorem ipsum 2018-10-30T23:20:00+00:00]]></title>
30+
<description><![CDATA[Ipsum velit cillum ad laborum sit nulla exercitation consequat sint veniam culpa veniam voluptate incididunt.]]></description>
31+
<link>http://example.com/test/1540941600</link>
32+
<guid isPermaLink="true">http://example.com/test/1540941600</guid>
33+
<dc:creator><![CDATA[John Smith]]></dc:creator>
34+
<pubDate>Tue, 30 Oct 2018 23:20:00 GMT</pubDate>
35+
</entry>
36+
<entry>
37+
<title><![CDATA[Lorem ipsum 2018-10-30T23:19:00+00:00]]></title>
38+
<description><![CDATA[Ullamco pariatur aliqua consequat ea veniam id qui incididunt laborum.]]></description>
39+
<link>http://example.com/test/1540941540</link>
40+
<guid isPermaLink="true">http://example.com/test/1540941540</guid>
41+
<dc:creator><![CDATA[John Smith]]></dc:creator>
42+
<pubDate>Tue, 30 Oct 2018 23:19:00 GMT</pubDate>
43+
</entry>
44+
<entry>
45+
<title><![CDATA[Lorem ipsum 2018-10-30T23:18:00+00:00]]></title>
46+
<description><![CDATA[Velit proident aliquip aliquip anim mollit voluptate laboris voluptate et occaecat occaecat laboris ea nulla.]]></description>
47+
<link>http://example.com/test/1540941480</link>
48+
<guid isPermaLink="true">http://example.com/test/1540941480</guid>
49+
<dc:creator><![CDATA[John Smith]]></dc:creator>
50+
<pubDate>Tue, 30 Oct 2018 23:18:00 GMT</pubDate>
51+
</entry>
52+
<entry>
53+
<title><![CDATA[Lorem ipsum 2018-10-30T23:17:00+00:00]]></title>
54+
<description><![CDATA[Do in quis mollit consequat id in minim laborum sint exercitation laborum elit officia.]]></description>
55+
<link>http://example.com/test/1540941420</link>
56+
<guid isPermaLink="true">http://example.com/test/1540941420</guid>
57+
<dc:creator><![CDATA[John Smith]]></dc:creator>
58+
<pubDate>Tue, 30 Oct 2018 23:17:00 GMT</pubDate>
59+
</entry>
60+
<entry>
61+
<title><![CDATA[Lorem ipsum 2018-10-30T23:16:00+00:00]]></title>
62+
<description><![CDATA[Irure id sint ullamco Lorem magna consectetur officia adipisicing duis incididunt.]]></description>
63+
<link>http://example.com/test/1540941360</link>
64+
<guid isPermaLink="true">http://example.com/test/1540941360</guid>
65+
<dc:creator><![CDATA[John Smith]]></dc:creator>
66+
<pubDate>Tue, 30 Oct 2018 23:16:00 GMT</pubDate>
67+
</entry>
68+
<entry>
69+
<title><![CDATA[Lorem ipsum 2018-10-30T23:15:00+00:00]]></title>
70+
<description><![CDATA[Sunt anim excepteur esse nisi commodo culpa laborum exercitation ad anim ex elit.]]></description>
71+
<link>http://example.com/test/1540941300</link>
72+
<guid isPermaLink="true">http://example.com/test/1540941300</guid>
73+
<dc:creator><![CDATA[John Smith]]></dc:creator>
74+
<pubDate>Tue, 30 Oct 2018 23:15:00 GMT</pubDate>
75+
</entry>
76+
<entry>
77+
<title><![CDATA[Lorem ipsum 2018-10-30T23:14:00+00:00]]></title>
78+
<description><![CDATA[Excepteur aliquip fugiat ex labore nisi.]]></description>
79+
<link>http://example.com/test/1540941240</link>
80+
<guid isPermaLink="true">http://example.com/test/1540941240</guid>
81+
<dc:creator><![CDATA[John Smith]]></dc:creator>
82+
<pubDate>Tue, 30 Oct 2018 23:14:00 GMT</pubDate>
83+
</entry>
84+
<entry>
85+
<title><![CDATA[Lorem ipsum 2018-10-30T23:13:00+00:00]]></title>
86+
<description><![CDATA[Id proident adipisicing proident pariatur aute pariatur pariatur dolor dolor in voluptate dolor.]]></description>
87+
<link>http://example.com/test/1540941180</link>
88+
<guid isPermaLink="true">http://example.com/test/1540941180</guid>
89+
<dc:creator><![CDATA[John Smith]]></dc:creator>
90+
<pubDate>Tue, 30 Oct 2018 23:13:00 GMT</pubDate>
91+
</entry>
92+
</feed>

0 commit comments

Comments
 (0)