mirror of
https://github.com/Jguer/yay
synced 2024-10-05 23:59:13 +00:00
test(news): add test case for edge case of news in same day as build
This commit is contained in:
parent
555d1ead95
commit
84e872ebe3
3
pkg/news/.snapshots/TestPrintNewsFeedSameDay
Normal file
3
pkg/news/.snapshots/TestPrintNewsFeedSameDay
Normal file
|
@ -0,0 +1,3 @@
|
|||
[1m[35m2020-04-14[0m[0m [1mzn_poly 0.9.2-2 update requires manual intervention[0m
|
||||
The zn_poly package prior to version 0.9.2-2 was missing a soname link.[0m
|
||||
|
|
@ -13,6 +13,27 @@ import (
|
|||
"gopkg.in/h2non/gock.v1"
|
||||
)
|
||||
|
||||
const lastNews = `
|
||||
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
||||
<channel>
|
||||
<title>Arch Linux: Recent news updates</title>
|
||||
<link>https://www.archlinux.org/news/</link>
|
||||
<description>The latest and greatest news from the Arch Linux distribution.</description>
|
||||
<atom:link href="https://www.archlinux.org/feeds/news/" rel="self" />
|
||||
<language>en-us</language>
|
||||
<lastBuildDate>Tue, 14 Apr 2020 16:30:32 +0000</lastBuildDate>
|
||||
<item>
|
||||
<title>zn_poly 0.9.2-2 update requires manual intervention</title>
|
||||
<link>https://www.archlinux.org/news/zn_poly-092-2-update-requires-manual-intervention/</link>
|
||||
<description><p>The zn_poly package prior to version 0.9.2-2 was missing a soname link.</description>
|
||||
<dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Antonio Rojas</dc:creator>
|
||||
<pubDate>Tue, 14 Apr 2020 16:30:30 +0000</pubDate>
|
||||
<guid isPermaLink="false">tag:www.archlinux.org,2020-04-14:/news/zn_poly-092-2-update-requires-manual-intervention/</guid>
|
||||
</item>
|
||||
</channel>
|
||||
</rss>
|
||||
`
|
||||
|
||||
const sampleNews = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Arch Linux: Recent news updates</title><link>https://www.archlinux.org/news/</link><description>The latest and greatest news from the Arch Linux distribution.</description><atom:link href="https://www.archlinux.org/feeds/news/" rel="self"></atom:link><language>en-us</language><lastBuildDate>Tue, 14 Apr 2020 16:30:32 +0000</lastBuildDate><item><title>zn_poly 0.9.2-2 update requires manual intervention</title><link>https://www.archlinux.org/news/zn_poly-092-2-update-requires-manual-intervention/</link><description><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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue