-
Notifications
You must be signed in to change notification settings - Fork 0
/
marshal_feedreader_test.go
177 lines (169 loc) · 4.44 KB
/
marshal_feedreader_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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright (c) VirtualTam
// SPDX-License-Identifier: MIT
package opml
import (
"encoding/xml"
"path/filepath"
"testing"
)
var (
feedReaderDocumentFeedly = Document{
XMLName: xml.Name{Local: "opml"},
Version: Version1,
Head: Head{
Title: "My subscriptions in feedly Cloud",
},
Body: Body{
Outlines: []Outline{
{
Text: "Programming",
Title: "Programming",
Outlines: []Outline{
{
Text: "Elixir Lang",
Title: "Elixir Lang",
Type: OutlineTypeSubscription,
HtmlUrl: "http://elixir-lang.org",
XmlUrl: "https://feeds.feedburner.com/ElixirLang",
},
{
Text: "Zephyr Project",
Title: "Zephyr Project",
Type: OutlineTypeSubscription,
HtmlUrl: "https://www.zephyrproject.org",
XmlUrl: "https://www.zephyrproject.org/feed/",
},
{
Text: "Python Insider",
Title: "Python Insider",
Type: OutlineTypeSubscription,
HtmlUrl: "https://pythoninsider.blogspot.com/",
XmlUrl: "https://feeds.feedburner.com/PythonInsider",
},
},
},
{
Text: "Games",
Title: "Games",
Outlines: []Outline{
{
Text: "BeamNG.drive",
Title: "BeamNG.drive",
Type: OutlineTypeSubscription,
HtmlUrl: "https://www.beamng.com/game/",
XmlUrl: "https://www.beamng.com/game/index.xml",
},
{
Text: "Vintage Story",
Title: "Vintage Story",
Type: OutlineTypeSubscription,
HtmlUrl: "https://www.vintagestory.at/blog.html/",
XmlUrl: "https://www.vintagestory.at/blog.html/?rss=1",
},
},
},
},
},
}
feedReaderDocumentNewsblur = Document{
XMLName: xml.Name{Local: "opml"},
Version: Version1_1,
Head: Head{
Title: "NewsBlur Feeds",
DateCreated: mustDecodeRFC1123Time("Thu, 07 Nov 2024 20:18:01.109756 GMT"),
DateModified: mustDecodeRFC1123Time("Thu, 07 Nov 2024 20:18:01.109756 GMT"),
},
Body: Body{
Outlines: []Outline{
{
Text: "Security",
Title: "Security",
Outlines: []Outline{
{
Text: "Google Online Security Blog",
Title: "Google Online Security Blog",
Type: OutlineTypeSubscription,
Version: RSSVersion1,
HtmlUrl: "http://security.googleblog.com/",
XmlUrl: "http://www.blogger.com/feeds/1176949257541686127/posts/default?max-results=25&redirect=false&start-index=26",
},
{
Text: "Blog on Library",
Title: "Blog on Library",
Type: OutlineTypeSubscription,
Version: RSSVersion1,
HtmlUrl: "https://www.openssl.org/blog/",
XmlUrl: "https://openssl-library.org:443/post/atom.xml",
},
{
Text: "Schneier on Security",
Title: "Schneier on Security",
Type: OutlineTypeSubscription,
Version: RSSVersion1,
HtmlUrl: "https://www.schneier.com",
XmlUrl: "https://www.schneier.com/feed/atom/",
},
},
},
{
Text: "Self-Hosted",
Title: "Self-Hosted",
},
{
Text: "Cryptography",
Title: "Cryptography",
},
{
Text: "Programming",
Title: "Programming",
Outlines: []Outline{
{
Text: "Git Rev News",
Title: "Git Rev News",
Type: OutlineTypeSubscription,
Version: RSSVersion1,
HtmlUrl: "https://git.github.io/rev_news/",
XmlUrl: "https://git.github.io/feed.xml",
},
{
Text: "The Go Programming Language Blog",
Title: "The Go Programming Language Blog",
Type: OutlineTypeSubscription,
Version: RSSVersion1,
HtmlUrl: "tag:blog.golang.org,2013:blog.golang.org",
XmlUrl: "https://go.dev/blog/feed.atom",
},
},
},
},
},
}
)
func TestUnmarshalFeedReader(t *testing.T) {
cases := []struct {
tname string
inputFileName string
want Document
}{
{
tname: "feedly",
inputFileName: "feedly.opml",
want: feedReaderDocumentFeedly,
},
{
tname: "newsblur",
inputFileName: "newsblur.opml",
want: feedReaderDocumentNewsblur,
},
}
for _, tc := range cases {
t.Run(tc.tname, func(t *testing.T) {
inputFilePath := filepath.Join("testdata", "feedreader", tc.inputFileName)
got, err := UnmarshalFile(inputFilePath)
if err != nil {
t.Fatalf("want no error, got %q", err)
}
AssertDocumentsEqual(t, *got, tc.want)
})
}
}