From 3cd999ac2ed914eb2d0c76e31261b4416a84d9ca Mon Sep 17 00:00:00 2001 From: Evgeny Kuznetsov Date: Wed, 5 Feb 2020 20:27:25 +0300 Subject: don't panic when feed image can't be parsed --- main_test.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'main_test.go') 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", -- cgit v1.2.3