news_test.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //go:build !integration
  2. // +build !integration
  3. package news
  4. import (
  5. "context"
  6. "io"
  7. "net/http"
  8. "os"
  9. "testing"
  10. "time"
  11. "github.com/bradleyjkemp/cupaloy"
  12. "github.com/stretchr/testify/assert"
  13. "gopkg.in/h2non/gock.v1"
  14. )
  15. const lastNews = `
  16. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  17. <channel>
  18. <title>Arch Linux: Recent news updates</title>
  19. <link>https://www.archlinux.org/news/</link>
  20. <description>The latest and greatest news from the Arch Linux distribution.</description>
  21. <atom:link href="https://www.archlinux.org/feeds/news/" rel="self" />
  22. <language>en-us</language>
  23. <lastBuildDate>Tue, 14 Apr 2020 16:30:32 +0000</lastBuildDate>
  24. <item>
  25. <title>zn_poly 0.9.2-2 update requires manual intervention</title>
  26. <link>https://www.archlinux.org/news/zn_poly-092-2-update-requires-manual-intervention/</link>
  27. <description>&lt;p&gt;The zn_poly package prior to version 0.9.2-2 was missing a soname link.</description>
  28. <dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Antonio Rojas</dc:creator>
  29. <pubDate>Tue, 14 Apr 2020 16:30:30 +0000</pubDate>
  30. <guid isPermaLink="false">tag:www.archlinux.org,2020-04-14:/news/zn_poly-092-2-update-requires-manual-intervention/</guid>
  31. </item>
  32. </channel>
  33. </rss>
  34. `
  35. const sampleNews = `<?xml version="1.0" encoding="utf-8"?>
  36. <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>&lt;p&gt;The zn_poly package prior to version 0.9.2-2 was missing a soname link.
  37. This has been fixed in 0.9.2-2, so the upgrade will need to overwrite the
  38. untracked files created by ldconfig. If you get an error&lt;/p&gt;
  39. &lt;pre&gt;&lt;code&gt;zn_poly: /usr/lib/libzn_poly-0.9.so exists in filesystem
  40. &lt;/code&gt;&lt;/pre&gt;
  41. &lt;p&gt;when updating, use&lt;/p&gt;
  42. &lt;pre&gt;&lt;code&gt;pacman -Syu --overwrite usr/lib/libzn_poly-0.9.so
  43. &lt;/code&gt;&lt;/pre&gt;
  44. &lt;p&gt;to perform the upgrade.&lt;/p&gt;</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><item><title>nss&gt;=3.51.1-1 and lib32-nss&gt;=3.51.1-1 updates require manual intervention</title><link>https://www.archlinux.org/news/nss3511-1-and-lib32-nss3511-1-updates-require-manual-intervention/</link><description>&lt;p&gt;The nss and lib32-nss packages prior to version 3.51.1-1 were missing a soname link each. This has been fixed in 3.51.1-1, so the upgrade will need to overwrite the untracked files created by ldconfig. If you get any of these errors&lt;/p&gt;
  45. &lt;pre&gt;&lt;code&gt;nss: /usr/lib/p11-kit-trust.so exists in filesystem
  46. lib32-nss: /usr/lib32/p11-kit-trust.so exists in filesystem
  47. &lt;/code&gt;&lt;/pre&gt;
  48. &lt;p&gt;when updating, use&lt;/p&gt;
  49. &lt;pre&gt;&lt;code&gt;pacman -Syu --overwrite /usr/lib\*/p11-kit-trust.so
  50. &lt;/code&gt;&lt;/pre&gt;
  51. &lt;p&gt;to perform the upgrade.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jan Alexander Steffens</dc:creator><pubDate>Mon, 13 Apr 2020 00:35:58 +0000</pubDate><guid isPermaLink="false">tag:www.archlinux.org,2020-04-13:/news/nss3511-1-and-lib32-nss3511-1-updates-require-manual-intervention/</guid></item><item><title>hplip 3.20.3-2 update requires manual intervention</title><link>https://www.archlinux.org/news/hplip-3203-2-update-requires-manual-intervention/</link><description>&lt;p&gt;The hplip package prior to version 3.20.3-2 was missing the compiled
  52. python modules. This has been fixed in 3.20.3-2, so the upgrade will
  53. need to overwrite the untracked pyc files that were created. If you get errors
  54. such as these&lt;/p&gt;
  55. &lt;pre&gt;&lt;code&gt;hplip: /usr/share/hplip/base/__pycache__/__init__.cpython-38.pyc exists in filesystem
  56. hplip: /usr/share/hplip/base/__pycache__/avahi.cpython-38.pyc exists in filesystem
  57. hplip: /usr/share/hplip/base/__pycache__/codes.cpython-38.pyc exists in filesystem
  58. ...many more...
  59. &lt;/code&gt;&lt;/pre&gt;
  60. &lt;p&gt;when updating, use&lt;/p&gt;
  61. &lt;pre&gt;&lt;code&gt;pacman -Suy --overwrite /usr/share/hplip/\*
  62. &lt;/code&gt;&lt;/pre&gt;
  63. &lt;p&gt;to perform the upgrade.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andreas Radke</dc:creator><pubDate>Thu, 19 Mar 2020 06:53:30 +0000</pubDate><guid isPermaLink="false">tag:www.archlinux.org,2020-03-19:/news/hplip-3203-2-update-requires-manual-intervention/</guid></item><item><title>firewalld&gt;=0.8.1-2 update requires manual intervention</title><link>https://www.archlinux.org/news/firewalld081-2-update-requires-manual-intervention/</link><description>&lt;p&gt;The firewalld package prior to version 0.8.1-2 was missing the compiled python modules. This has been fixed in 0.8.1-2, so the upgrade will need to overwrite the untracked pyc files created. If you get errors like these&lt;/p&gt;
  64. &lt;pre&gt;&lt;code&gt;firewalld: /usr/lib/python3.8/site-packages/firewall/__pycache__/__init__.cpython-38.pyc exists in filesystem
  65. firewalld: /usr/lib/python3.8/site-packages/firewall/__pycache__/client.cpython-38.pyc exists in filesystem
  66. firewalld: /usr/lib/python3.8/site-packages/firewall/__pycache__/dbus_utils.cpython-38.pyc exists in filesystem
  67. ...many more...
  68. &lt;/code&gt;&lt;/pre&gt;
  69. &lt;p&gt;when updating, use&lt;/p&gt;
  70. &lt;pre&gt;&lt;code&gt;pacman -Suy --overwrite /usr/lib/python3.8/site-packages/firewall/\*
  71. &lt;/code&gt;&lt;/pre&gt;
  72. &lt;p&gt;to perform the upgrade.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jan Alexander Steffens</dc:creator><pubDate>Sun, 01 Mar 2020 16:36:48 +0000</pubDate><guid isPermaLink="false">tag:www.archlinux.org,2020-03-01:/news/firewalld081-2-update-requires-manual-intervention/</guid></item><item><title>The Future of the Arch Linux Project Leader</title><link>https://www.archlinux.org/news/the-future-of-the-arch-linux-project-leader/</link><description>&lt;p&gt;Hello everyone,&lt;/p&gt;
  73. &lt;p&gt;Some of you may know me from the days when I was much more involved in Arch, but most of you probably just know me as a name on the website. I’ve been with Arch for some time, taking the leadership of this beast over from Judd back in 2007. But, as these things often go, my involvement has slid down to minimal levels over time. It’s high time that changes.&lt;/p&gt;
  74. &lt;p&gt;Arch Linux needs involved leadership to make hard decisions and direct the project where it needs to go. And I am not in a position to do this.&lt;/p&gt;
  75. &lt;p&gt;In a team effort, the Arch Linux staff devised a new process for determining future leaders. From now on, leaders will be elected by the staff for a term length of two years. Details of this new process can be found &lt;a href="https://wiki.archlinux.org/index.php/DeveloperWiki:Project_Leader"&gt;here&lt;/a&gt;&lt;/p&gt;
  76. &lt;p&gt;In the first official vote with Levente Polyak (anthraxx), Gaetan Bisson (vesath), Giancarlo Razzolini (grazzolini), and Sven-Hendrik Haase (svenstaro) as candidates, and through 58 verified votes, a winner was chosen:&lt;/p&gt;
  77. &lt;p&gt;&lt;strong&gt;Levente Polyak (anthraxx) will be taking over the reins of this ship. Congratulations!&lt;/strong&gt;&lt;/p&gt;
  78. &lt;p&gt;&lt;em&gt;Thanks for everything over all these years,&lt;br /&gt;
  79. Aaron Griffin (phrakture)&lt;/em&gt;&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Aaron Griffin</dc:creator><pubDate>Mon, 24 Feb 2020 15:56:28 +0000</pubDate><guid isPermaLink="false">tag:www.archlinux.org,2020-02-24:/news/the-future-of-the-arch-linux-project-leader/</guid></item><item><title>Planet Arch Linux migration</title><link>https://www.archlinux.org/news/planet-arch-linux-migration/</link><description>&lt;p&gt;The software behind planet.archlinux.org was implemented in Python 2 and is no longer maintained upstream. This functionality has now been implemented in archlinux.org's archweb backend which is actively maintained but offers a slightly different experience.&lt;/p&gt;
  80. &lt;p&gt;The most notable changes are the offered feeds and the feed location. Archweb only offers an Atom feed which is located at &lt;a href="https://archlinux.org/feeds/planet"&gt;here&lt;/a&gt;.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Jelle van der Waa</dc:creator><pubDate>Sat, 22 Feb 2020 22:43:00 +0000</pubDate><guid isPermaLink="false">tag:www.archlinux.org,2020-02-22:/news/planet-arch-linux-migration/</guid></item><item><title>sshd needs restarting after upgrading to openssh-8.2p1</title><link>https://www.archlinux.org/news/sshd-needs-restarting-after-upgrading-to-openssh-82p1/</link><description>&lt;p&gt;After upgrading to openssh-8.2p1, the existing SSH daemon will be unable to accept new connections. (See &lt;a href="https://bugs.archlinux.org/task/65517"&gt;FS#65517&lt;/a&gt;.) When upgrading remote hosts, please make sure to restart the SSH daemon using &lt;code&gt;systemctl restart sshd&lt;/code&gt; right after running &lt;code&gt;pacman -Syu&lt;/code&gt;. If you are upgrading to openssh-8.2p1-3 or higher, this restart will happen automatically.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Gaetan Bisson</dc:creator><pubDate>Mon, 17 Feb 2020 01:35:04 +0000</pubDate><guid isPermaLink="false">tag:www.archlinux.org,2020-02-17:/news/sshd-needs-restarting-after-upgrading-to-openssh-82p1/</guid></item><item><title>rsync compatibility</title><link>https://www.archlinux.org/news/rsync-compatibility/</link><description>&lt;p&gt;Our &lt;code&gt;rsync&lt;/code&gt; package was shipped with bundled &lt;code&gt;zlib&lt;/code&gt; to provide compatibility
  81. with the old-style &lt;code&gt;--compress&lt;/code&gt; option up to version 3.1.0. Version 3.1.1 was
  82. released on 2014-06-22 and is shipped by all major distributions now.&lt;/p&gt;
  83. &lt;p&gt;So we decided to finally drop the bundled library and ship a package with
  84. system &lt;code&gt;zlib&lt;/code&gt;. This also fixes security issues, actual ones and in future. Go
  85. and blame those running old versions if you encounter errors with &lt;code&gt;rsync
  86. 3.1.3-3&lt;/code&gt;.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Christian Hesse</dc:creator><pubDate>Wed, 15 Jan 2020 20:14:43 +0000</pubDate><guid isPermaLink="false">tag:www.archlinux.org,2020-01-15:/news/rsync-compatibility/</guid></item><item><title>Now using Zstandard instead of xz for package compression</title><link>https://www.archlinux.org/news/now-using-zstandard-instead-of-xz-for-package-compression/</link><description>&lt;p&gt;As announced on the &lt;a href="https://lists.archlinux.org/pipermail/arch-dev-public/2019-December/029752.html"&gt;mailing list&lt;/a&gt;, on Friday, Dec 27 2019, our package compression scheme has changed from xz (.pkg.tar.xz) to &lt;a href="https://lists.archlinux.org/pipermail/arch-dev-public/2019-December/029778.html"&gt;zstd (.pkg.tar.zst)&lt;/a&gt;.&lt;/p&gt;
  87. &lt;p&gt;zstd and xz trade blows in their compression ratio. Recompressing all packages to zstd with our options yields a total ~0.8% increase in package size on all of our packages combined, but the decompression time for all packages saw a ~1300% speedup.&lt;/p&gt;
  88. &lt;p&gt;We already have more than 545 zstd-compressed packages in our repositories, and as packages get updated more will keep rolling in. We have not found any user-facing issues as of yet, so things appear to be working.&lt;/p&gt;
  89. &lt;p&gt;As a packager, you will automatically start building .pkg.tar.zst packages if you are using the latest version of devtools (&amp;gt;= 20191227).&lt;br /&gt;
  90. As an end-user no manual intervention is required, assuming that you have read and followed the news post &lt;a href="https://www.archlinux.org/news/required-update-to-recent-libarchive/"&gt;from late last year&lt;/a&gt;.&lt;/p&gt;
  91. &lt;p&gt;If you nevertheless haven't updated libarchive since 2018, all hope is not lost! Binary builds of pacman-static are available from Eli Schwartz' &lt;a href="https://wiki.archlinux.org/index.php/Unofficial_user_repositories#eschwartz"&gt;personal repository&lt;/a&gt; (or direct link to &lt;a href="https://pkgbuild.com/~eschwartz/repo/x86_64-extracted/"&gt;binary&lt;/a&gt;), signed with their Trusted User keys, with which you can perform the update.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Robin Broda</dc:creator><pubDate>Sat, 04 Jan 2020 20:35:55 +0000</pubDate><guid isPermaLink="false">tag:www.archlinux.org,2020-01-04:/news/now-using-zstandard-instead-of-xz-for-package-compression/</guid></item><item><title>Xorg cleanup requires manual intervention</title><link>https://www.archlinux.org/news/xorg-cleanup-requires-manual-intervention/</link><description>&lt;p&gt;In the process of &lt;a href="https://bugs.archlinux.org/task/64892"&gt;Xorg cleanup&lt;/a&gt; the update requires manual
  92. intervention when you hit this message:&lt;/p&gt;
  93. &lt;pre&gt;&lt;code&gt;:: installing xorgproto (2019.2-2) breaks dependency 'inputproto' required by lib32-libxi
  94. :: installing xorgproto (2019.2-2) breaks dependency 'dmxproto' required by libdmx
  95. :: installing xorgproto (2019.2-2) breaks dependency 'xf86dgaproto' required by libxxf86dga
  96. :: installing xorgproto (2019.2-2) breaks dependency 'xf86miscproto' required by libxxf86misc
  97. &lt;/code&gt;&lt;/pre&gt;
  98. &lt;p&gt;when updating, use: &lt;code&gt;pacman -Rdd libdmx libxxf86dga libxxf86misc &amp;amp;&amp;amp; pacman -Syu&lt;/code&gt; to perform the upgrade.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Andreas Radke</dc:creator><pubDate>Fri, 20 Dec 2019 13:37:40 +0000</pubDate><guid isPermaLink="false">tag:www.archlinux.org,2019-12-20:/news/xorg-cleanup-requires-manual-intervention/</guid></item></channel></rss>
  99. `
  100. func TestPrintNewsFeed(t *testing.T) {
  101. layout := "2006-01-02"
  102. str := "2020-04-13"
  103. lastNewsTime, _ := time.Parse(layout, str)
  104. type args struct {
  105. cutOffDate time.Time
  106. bottomUp bool
  107. all bool
  108. quiet bool
  109. }
  110. tests := []struct {
  111. name string
  112. args args
  113. wantErr bool
  114. }{
  115. {name: "all-verbose", args: args{bottomUp: true, cutOffDate: time.Now(), all: true, quiet: false}, wantErr: false},
  116. {name: "all-quiet", args: args{bottomUp: true, cutOffDate: lastNewsTime, all: true, quiet: true}, wantErr: false},
  117. {name: "latest-quiet", args: args{bottomUp: true, cutOffDate: lastNewsTime, all: false, quiet: true}, wantErr: false},
  118. {name: "latest-quiet-topdown", args: args{bottomUp: false, cutOffDate: lastNewsTime, all: false, quiet: true}, wantErr: false},
  119. }
  120. t.Setenv("TZ", "UTC")
  121. for _, tt := range tests {
  122. tt := tt
  123. t.Run(tt.name, func(t *testing.T) {
  124. gock.New("https://archlinux.org").
  125. Get("/feeds/news").
  126. Reply(200).
  127. BodyString(sampleNews)
  128. defer gock.Off()
  129. rescueStdout := os.Stdout
  130. r, w, _ := os.Pipe()
  131. os.Stdout = w
  132. err := PrintNewsFeed(context.Background(), &http.Client{}, tt.args.cutOffDate, tt.args.bottomUp, tt.args.all, tt.args.quiet)
  133. assert.NoError(t, err)
  134. w.Close()
  135. out, _ := io.ReadAll(r)
  136. cupaloy.SnapshotT(t, out)
  137. os.Stdout = rescueStdout
  138. })
  139. }
  140. }
  141. // GIVEN last build time at 13h00
  142. // WHEN there's a news posted at 18h00
  143. // THEN it should still be printed
  144. func TestPrintNewsFeedSameDay(t *testing.T) {
  145. str := "2020-04-14T13:04:05Z"
  146. lastNewsTime, _ := time.Parse(time.RFC3339, str)
  147. gock.New("https://archlinux.org").
  148. Get("/feeds/news").
  149. Reply(200).
  150. BodyString(lastNews)
  151. defer gock.Off()
  152. rescueStdout := os.Stdout
  153. r, w, _ := os.Pipe()
  154. os.Stdout = w
  155. err := PrintNewsFeed(context.Background(), &http.Client{}, lastNewsTime, true, false, false)
  156. assert.NoError(t, err)
  157. w.Close()
  158. out, _ := io.ReadAll(r)
  159. cupaloy.SnapshotT(t, out)
  160. os.Stdout = rescueStdout
  161. }