aboutsummaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
authorEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-01-28 20:50:24 +0300
committerEvgeny Kuznetsov <evgeny@kuznetsov.md>2020-01-28 20:50:24 +0300
commit60d88d0bc841b1b48fd2a5262dc6723d63e4d641 (patch)
tree3ef60f15b8b83e339deecee35bf798d273f73d78 /main_test.go
parentc13ee4fe746f4ba5fd48f926f3315284e66193f3 (diff)
downloadradiorus-rss-60d88d0bc841b1b48fd2a5262dc6723d63e4d641.tar.gz
radiorus-rss-60d88d0bc841b1b48fd2a5262dc6723d63e4d641.zip
improve test coverage
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/main_test.go b/main_test.go
index fab7129..f24880c 100644
--- a/main_test.go
+++ b/main_test.go
@@ -20,10 +20,13 @@ import (
"flag"
"fmt"
"io/ioutil"
+ "log"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
+ "strings"
+ "sync"
"testing"
"github.com/gorilla/feeds"
@@ -74,6 +77,30 @@ func TestFeed(t *testing.T) {
}
}
+func TestMissingEpisode(t *testing.T) {
+ server := helperMockServer(t)
+ defer helperCleanupServer(t)
+
+ item := feeds.Item{
+ Id: "aabb",
+ Link: &feeds.Link{Href: fmt.Sprintf("%s/brand/none", server.URL)},
+ }
+
+ var buf bytes.Buffer
+ log.SetOutput(&buf)
+ defer func() { log.SetOutput(os.Stderr) }()
+
+ var wg sync.WaitGroup
+ wg.Add(1)
+ describeEpisode(&item, &wg)
+
+ got := string(buf.Bytes())
+ want := fmt.Sprintf("could not find episode description on page %v: %v", item.Link.Href, errCantParse)
+ if !strings.Contains(got, want) {
+ t.Fatalf("got %v, want %v", got, want)
+ }
+}
+
func TestServedFeed(t *testing.T) {
server := helperMockServer(t)
defer helperCleanupServer(t)
@@ -135,6 +162,6 @@ func TestEpisodeURLPrefix(t *testing.T) {
want := "http://www.radiorus.ru/brand/"
if got != want {
- t.Fatal(fmt.Sprintf("got %v, want %v", got, want))
+ t.Fatalf("got %v, want %v", got, want)
}
}