aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-01-28 22:06:46 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-01-28 22:06:46 +0300
commitba1af3d90e4b5d2a01cd42e558e0a53f342a2f75 (patch)
tree9fab6c26920dcdf6a1d07c9edd437c1c528456aa
parentf3a4c3e464285abd5db211c047f16dbc5ce82c32 (diff)
downloadradiorus-rss-ba1af3d90e4b5d2a01cd42e558e0a53f342a2f75.tar.gz
radiorus-rss-ba1af3d90e4b5d2a01cd42e558e0a53f342a2f75.zip
improve test coverage
-rw-r--r--main.go2
-rw-r--r--main_test.go29
2 files changed, 28 insertions, 3 deletions
diff --git a/main.go b/main.go
index 990516e..c34dcf4 100644
--- a/main.go
+++ b/main.go
@@ -122,7 +122,7 @@ func getFeed(url string) (feed *feeds.Feed) {
func populateFeed(feed *feeds.Feed, page []byte) (err error) {
titleMatch := programNameRe.FindSubmatch(page)
if len(titleMatch) < 1 {
- return fmt.Errorf("bad program page")
+ return fmt.Errorf("bad programme page")
}
feed.Title = string(titleMatch[1])
diff --git a/main_test.go b/main_test.go
index d7210be..8aa272d 100644
--- a/main_test.go
+++ b/main_test.go
@@ -24,6 +24,7 @@ import (
"net/http"
"net/http/httptest"
"os"
+ "os/exec"
"path/filepath"
"strings"
"sync"
@@ -50,13 +51,18 @@ func helperLoadBytes(t testing.TB, name string) []byte {
}
func TestFeed(t *testing.T) {
- page := helperLoadBytes(t, "episodes")
- page = cleanText(page)
+ var page []byte
feed := &feeds.Feed{
Link: &feeds.Link{Href: "http://www.radiorus.ru/brand/57083/episodes"},
}
+ err := populateFeed(feed, page)
+ assertStringContains(t, fmt.Sprint(err), "bad programme")
+
+ page = helperLoadBytes(t, "episodes")
+ page = cleanText(page)
+
if err := populateFeed(feed, page); err != nil {
t.Fatal(err)
}
@@ -117,6 +123,25 @@ func TestMissingFeedDesc(t *testing.T) {
assertStringContains(t, buf.String(), fmt.Sprintf("could not find programme description on page %v: %v", server.URL+"/brand/57083/about", errCantParse))
}
+func TestMissingFeed(t *testing.T) {
+ server := helperMockServer(t)
+ defer helperCleanupServer(t)
+
+ if os.Getenv("DO_CRASH") == "1" {
+ processURL(fmt.Sprintf("%s/brand/57084/episodes", server.URL))
+ return
+ }
+
+ cmd := exec.Command(os.Args[0], "-test.run=TestMissingFeed")
+ cmd.Env = append(os.Environ(), "DO_CRASH=1")
+ out, err := cmd.CombinedOutput()
+ if e, ok := err.(*exec.ExitError); !(ok && !e.Success()) {
+ t.Fatalf("process ran with err %v, want exit status 1", err)
+ }
+
+ assertStringContains(t, string(out), fmt.Sprint("84/episodes: bad programme page"))
+}
+
func TestServedFeed(t *testing.T) {
server := helperMockServer(t)
defer helperCleanupServer(t)