aboutsummaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-02-05 20:27:25 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-02-05 20:27:25 +0300
commit3cd999ac2ed914eb2d0c76e31261b4416a84d9ca (patch)
tree5723bec595e13678b15506f43cf33582aa9eea47 /main_test.go
parent789eb9f24ac72505ef8bd89d6c94a99ba9d7efad (diff)
downloadradiorus-rss-3cd999ac2ed914eb2d0c76e31261b4416a84d9ca.tar.gz
radiorus-rss-3cd999ac2ed914eb2d0c76e31261b4416a84d9ca.zip
don't panic when feed image can't be parsed
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/main_test.go b/main_test.go
index d00a6ae..a85b65d 100644
--- a/main_test.go
+++ b/main_test.go
@@ -57,9 +57,16 @@ func assertGolden(t *testing.T, actual []byte, golden string) {
t.Helper()
if *update {
- writeFile(actual, golden)
+ if _, err := os.Stat(golden); os.IsNotExist(err) {
+ writeFile(actual, golden)
+ } else {
+ t.Log("file", golden, "exists, remove it to record new golden result")
+ }
+ }
+ expected, err := ioutil.ReadFile(golden)
+ if err != nil {
+ t.Error("no file:", golden)
}
- expected, _ := ioutil.ReadFile(golden)
if !bytes.Equal(actual, expected) {
t.Fail()
@@ -107,6 +114,23 @@ func TestBadEpisode(t *testing.T) {
}
}
+func TestNoImage(t *testing.T) {
+ feed := &feeds.Feed{
+ Link: &feeds.Link{Href: "http://www.radiorus.ru/brand/57083/episodes"},
+ }
+
+ page := helperLoadBytes(t, "episodes.noimg")
+ page = cleanText(page)
+
+ if err := populateFeed(feed, page); err != nil {
+ t.Fatal(err)
+ }
+
+ actual := createFeed(feed)
+ golden := filepath.Join("testdata", t.Name()+".golden")
+ assertGolden(t, actual, golden)
+}
+
func TestFindEpisodes(t *testing.T) {
var tests = []string{
"episodes",