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
|
// SPDX-License-Identifier: ISC
// Copyright © 2022 siddharth <s@ricketyspace.net>
package feed
import (
"net/url"
"testing"
"ricketyspace.net/fern/file"
)
func TestPodcastUnmarshal(t *testing.T) {
testFeeds := []string{
"testdata/pc-atp.xml",
"testdata/pc-daringfireball.xml",
"testdata/pc-kara.xml",
"testdata/pc-scwpod.xml",
}
for _, feed := range testFeeds {
bs, err := file.ReadFile(feed)
if err != nil {
t.Errorf("read feed: %v", err)
return
}
entries, err := podcastUnmarshal(bs)
if err != nil {
t.Errorf("feed unmarshal: %v", err)
return
}
for _, entry := range entries {
if len(entry.Id) < 1 {
t.Errorf("entry id: %v", entry.Id)
return
}
if len(entry.Title) < 1 {
t.Errorf("entry title: %v", entry.Title)
return
}
if entry.PubTime.Unix() < 994702392 {
t.Errorf("entry time: %v", entry.PubTime)
return
}
_, err = url.Parse(entry.Link)
if err != nil {
t.Errorf("entry link: %s: %v", entry.Link, err)
return
}
}
}
}
func TestUnmarshal(t *testing.T) {
testFeeds := map[string]string{
"podcast": "testdata/pc-daringfireball.xml",
}
for schema, feed := range testFeeds {
bs, err := file.ReadFile(feed)
if err != nil {
t.Errorf("read feed: %v", err)
return
}
feed := new(Feed)
feed.Schema = schema
if err = feed.unmarshal(bs); err != nil {
t.Errorf("feed unmarshal: %v", err)
return
}
for _, entry := range feed.Entries {
if len(entry.Id) < 1 {
t.Errorf("entry id: %v", entry.Id)
return
}
if len(entry.Title) < 1 {
t.Errorf("entry title: %v", entry.Title)
return
}
if entry.PubTime.Unix() < 994702392 {
t.Errorf("entry time: %v", entry.PubTime)
return
}
_, err = url.Parse(entry.Link)
if err != nil {
t.Errorf("entry link: %s: %v", entry.Link, err)
return
}
}
}
}
|