diff --git a/consume_test.go b/consume_test.go index 4dd771a..b472d8c 100644 --- a/consume_test.go +++ b/consume_test.go @@ -180,6 +180,193 @@ var testRssFeedXML = RssFeedXml{ }, } +var testAtomFeedXML = AtomFeed{ + XMLName: xml.Name{Space: "", Local: "feed"}, + Xmlns: "", + Title: "Lorem ipsum feed for an interval of 1 minutes", + Id: "", + Updated: "", + Category: "", + Icon: "", + Logo: "", + Rights: "", + Subtitle: "", + Link: &AtomLink{ + XMLName: xml.Name{Space: "", Local: "link"}, + Href: "", + Rel: "", + Type: "", + Length: "", + }, + Author: &AtomAuthor{ + XMLName: xml.Name{Space: "", Local: "author"}, + AtomPerson: AtomPerson{}, + }, + Contributor: (*AtomContributor)(nil), + Entries: []*AtomEntry{ + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:22:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:21:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:20:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:19:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:18:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:17:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:16:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:15:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:14:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + &AtomEntry{ + XMLName: xml.Name{Space: "", Local: "entry"}, + Xmlns: "", + Title: "Lorem ipsum 2018-10-30T23:13:00+00:00", + Updated: "", + Id: "", + Category: "", + Content: (*AtomContent)(nil), + Rights: "", + Source: "", + Published: "", + Contributor: (*AtomContributor)(nil), + Links: nil, + Summary: (*AtomSummary)(nil), + Author: (*AtomAuthor)(nil), + }, + }, +} + func TestRssUnmarshal(t *testing.T) { var xmlFeed RssFeedXml xmlFile, err := os.Open("test.rss") @@ -196,3 +383,19 @@ func TestRssUnmarshal(t *testing.T) { } } + +func TestAtomUnmarshal(t *testing.T) { + var xmlFeed AtomFeed + xmlFile, err := os.Open("test.atom") + if err != nil { + panic("AHH file bad") + } + bytes, _ := ioutil.ReadAll(xmlFile) + xml.Unmarshal(bytes, &xmlFeed) + + if !reflect.DeepEqual(testAtomFeedXML, xmlFeed) { + diffs := pretty.Diff(testAtomFeedXML, xmlFeed) + t.Log(pretty.Println(diffs)) + t.Error("object was not unmarshalled correctly") + } +} diff --git a/test.atom b/test.atom new file mode 100644 index 0000000..aa15214 --- /dev/null +++ b/test.atom @@ -0,0 +1,92 @@ + + + <![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