diff --git a/pkg/news/.snapshots/TestPrintNewsFeedSameDay b/pkg/news/.snapshots/TestPrintNewsFeedSameDay new file mode 100644 index 00000000..12cebc03 --- /dev/null +++ b/pkg/news/.snapshots/TestPrintNewsFeedSameDay @@ -0,0 +1,3 @@ +2020-04-14 zn_poly 0.9.2-2 update requires manual intervention +The zn_poly package prior to version 0.9.2-2 was missing a soname link. + diff --git a/pkg/news/news_test.go b/pkg/news/news_test.go index e692a346..72faa0f9 100644 --- a/pkg/news/news_test.go +++ b/pkg/news/news_test.go @@ -13,6 +13,27 @@ import ( "gopkg.in/h2non/gock.v1" ) +const lastNews = ` + + + Arch Linux: Recent news updates + https://www.archlinux.org/news/ + The latest and greatest news from the Arch Linux distribution. + + en-us + Tue, 14 Apr 2020 16:30:32 +0000 + + zn_poly 0.9.2-2 update requires manual intervention + https://www.archlinux.org/news/zn_poly-092-2-update-requires-manual-intervention/ + <p>The zn_poly package prior to version 0.9.2-2 was missing a soname link. + Antonio Rojas + Tue, 14 Apr 2020 16:30:30 +0000 + tag:www.archlinux.org,2020-04-14:/news/zn_poly-092-2-update-requires-manual-intervention/ + + + +` + const sampleNews = ` Arch Linux: Recent news updateshttps://www.archlinux.org/news/The latest and greatest news from the Arch Linux distribution.en-usTue, 14 Apr 2020 16:30:32 +0000zn_poly 0.9.2-2 update requires manual interventionhttps://www.archlinux.org/news/zn_poly-092-2-update-requires-manual-intervention/<p>The zn_poly package prior to version 0.9.2-2 was missing a soname link. This has been fixed in 0.9.2-2, so the upgrade will need to overwrite the @@ -125,3 +146,31 @@ func TestPrintNewsFeed(t *testing.T) { }) } } + +// GIVEN last build time at 13h00 +// WHEN there's a news posted at 18h00 +// THEN it should still be printed +func TestPrintNewsFeedSameDay(t *testing.T) { + t.Parallel() + str := "2020-04-14T13:04:05Z" + lastNewsTime, _ := time.Parse(time.RFC3339, str) + + gock.New("https://archlinux.org"). + Get("/feeds/news"). + Reply(200). + BodyString(lastNews) + + defer gock.Off() + + rescueStdout := os.Stdout + r, w, _ := os.Pipe() + os.Stdout = w + + err := PrintNewsFeed(context.TODO(), &http.Client{}, lastNewsTime, 0, false, false) + assert.NoError(t, err) + + w.Close() + out, _ := io.ReadAll(r) + cupaloy.SnapshotT(t, out) + os.Stdout = rescueStdout +}