forked from gorilla/feeds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
feed_test.go
118 lines (111 loc) · 4.32 KB
/
feed_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package feeds
import (
"testing"
"time"
)
var atomOutput = `<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">
<title>jmoiron.net blog</title>
<id>http://jmoiron.net/blog</id>
<updated>2013-01-16T21:52:35-05:00</updated>
<rights>This work is copyright © Benjamin Button</rights>
<subtitle>discussion about tech, footie, photos</subtitle>
<link href="http://jmoiron.net/blog"></link>
<author>
<name>Jason Moiron</name>
<email>[email protected]</email>
</author>
<entry>
<title>Limiting Concurrency in Go</title>
<updated>2013-01-16T21:52:35-05:00</updated>
<id>tag:jmoiron.net,2013-01-16:/blog/limiting-concurrency-in-go/</id>
<content type="html">A discussion on controlled parallelism in golang</content>
<link href="http://jmoiron.net/blog/limiting-concurrency-in-go/"></link>
<author>
<name>Jason Moiron</name>
<email>[email protected]</email>
</author>
</entry>
<entry>
<title>Logic-less Template Redux</title>
<updated>2013-01-16T21:52:35-05:00</updated>
<id>tag:jmoiron.net,2013-01-16:/blog/logicless-template-redux/</id>
<content type="html">More thoughts on logicless templates</content>
<link href="http://jmoiron.net/blog/logicless-template-redux/"></link>
</entry>
<entry>
<title>Idiomatic Code Reuse in Go</title>
<updated>2013-01-16T21:52:35-05:00</updated>
<id>tag:jmoiron.net,2013-01-16:/blog/idiomatic-code-reuse-in-go/</id>
<content type="html">How to use interfaces <em>effectively</em></content>
<link href="http://jmoiron.net/blog/idiomatic-code-reuse-in-go/"></link>
</entry>
</feed>`
var rssOutput = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0">
<channel>
<title>jmoiron.net blog</title>
<link>http://jmoiron.net/blog</link>
<description>discussion about tech, footie, photos</description>
<copyright>This work is copyright © Benjamin Button</copyright>
<managingEditor>[email protected] (Jason Moiron)</managingEditor>
<pubDate>2013-01-16T21:52:35-05:00</pubDate>
<item>
<title>Limiting Concurrency in Go</title>
<link>http://jmoiron.net/blog/limiting-concurrency-in-go/</link>
<description>A discussion on controlled parallelism in golang</description>
<author>Jason Moiron</author>
<pubDate>2013-01-16T21:52:35-05:00</pubDate>
</item>
<item>
<title>Logic-less Template Redux</title>
<link>http://jmoiron.net/blog/logicless-template-redux/</link>
<description>More thoughts on logicless templates</description>
<pubDate>2013-01-16T21:52:35-05:00</pubDate>
</item>
<item>
<title>Idiomatic Code Reuse in Go</title>
<link>http://jmoiron.net/blog/idiomatic-code-reuse-in-go/</link>
<description>How to use interfaces <em>effectively</em></description>
<pubDate>2013-01-16T21:52:35-05:00</pubDate>
</item>
</channel>
</rss>`
func TestFeed(t *testing.T) {
now, _ := time.Parse(time.RFC3339, "2013-01-16T21:52:35-05:00")
feed := &Feed{
Title: "jmoiron.net blog",
Link: &Link{Href: "http://jmoiron.net/blog"},
Description: "discussion about tech, footie, photos",
Author: &Author{"Jason Moiron", "[email protected]"},
Created: now,
Copyright: "This work is copyright © Benjamin Button",
}
feed.Items = []*Item{
&Item{
Title: "Limiting Concurrency in Go",
Link: &Link{Href: "http://jmoiron.net/blog/limiting-concurrency-in-go/"},
Description: "A discussion on controlled parallelism in golang",
Author: &Author{"Jason Moiron", "[email protected]"},
Created: now,
},
&Item{
Title: "Logic-less Template Redux",
Link: &Link{Href: "http://jmoiron.net/blog/logicless-template-redux/"},
Description: "More thoughts on logicless templates",
Created: now,
},
&Item{
Title: "Idiomatic Code Reuse in Go",
Link: &Link{Href: "http://jmoiron.net/blog/idiomatic-code-reuse-in-go/"},
Description: "How to use interfaces <em>effectively</em>",
Created: now,
},
}
atom, _ := feed.ToAtom()
rss, _ := feed.ToRss()
if atom != atomOutput {
t.Errorf("Atom not what was expected. Got:\n%s\n\nExpected:\n%s\n", atom, atomOutput)
}
if rss != rssOutput {
t.Errorf("Rss not what was expected. Got:\n%s\n\nExpected:\n%s\n", rss, rssOutput)
}
}