diff options
author | siddharth ravikumar <s@ricketyspace.net> | 2022-11-25 20:53:54 -0500 |
---|---|---|
committer | siddharth ravikumar <s@ricketyspace.net> | 2022-11-25 20:53:54 -0500 |
commit | 6196d58a8d6d432d799736fc9cf6740229f021c3 (patch) | |
tree | c8dcae340e02853cff174aa0c70fb047a1420979 /schema/schema_test.go | |
parent | 43ea9acb421baa6f3379af9ae4508dfb4bf339ab (diff) |
schema: add `PodcastFeed`
Diffstat (limited to 'schema/schema_test.go')
-rw-r--r-- | schema/schema_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/schema/schema_test.go b/schema/schema_test.go new file mode 100644 index 0000000..b80ad3f --- /dev/null +++ b/schema/schema_test.go @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: ISC +// Copyright © 2022 siddharth <s@ricketyspace.net> + +package schema + +import ( + "encoding/xml" + "net/url" + "testing" + "time" + + "ricketyspace.net/fern/file" +) + +func TestPodcastFeed(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 + } + pf := new(PodcastFeed) + err = xml.Unmarshal(bs, pf) + if err != nil { + t.Errorf("xml unmarshal: %v", err) + return + } + for _, entry := range pf.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 + } + layout := time.RFC1123Z + if entry.Pub[len(entry.Pub)-1:] == "T" { + // Textual time zone. like 'EDT'. + if entry.Pub[6:7] == " " { + layout = "Mon, 2 Jan 2006 15:04:05 MST" + } else { + layout = time.RFC1123 + } + } + pt, err := time.Parse(layout, entry.Pub) + if err != nil { + t.Errorf("entry pub: %v: '%v'", layout, entry.Pub) + return + } + if pt.Unix() < 994702392 { + t.Errorf("entry time: %v", pt) + return + } + _, err = url.Parse(entry.Link.Url) + if err != nil { + t.Errorf("entry url: %s: %v", entry.Link.Url, err) + return + } + } + } +} |