From 60d88d0bc841b1b48fd2a5262dc6723d63e4d641 Mon Sep 17 00:00:00 2001 From: Evgeny Kuznetsov Date: Tue, 28 Jan 2020 20:50:24 +0300 Subject: improve test coverage --- main_test.go | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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) } } -- cgit v1.2.3