|
| 1 | +// Copyright 2025 The Forgejo Authors. All rights reserved. |
| 2 | +// SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | + |
| 4 | +package integration |
| 5 | + |
| 6 | +import ( |
| 7 | + "net/http" |
| 8 | + "regexp" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "code.gitea.io/gitea/tests" |
| 12 | + |
| 13 | + "github.com/stretchr/testify/assert" |
| 14 | +) |
| 15 | + |
| 16 | +func TestReleaseFeed(t *testing.T) { |
| 17 | + defer tests.PrepareTestEnv(t)() |
| 18 | + |
| 19 | + normalize := func(body string) string { |
| 20 | + // Remove port. |
| 21 | + body = regexp.MustCompile(`localhost:\d+`).ReplaceAllString(body, "localhost") |
| 22 | + // date is timezone dependent. |
| 23 | + body = regexp.MustCompile(`<pubDate>.*</pubDate>`).ReplaceAllString(body, "<pubDate></pubDate>") |
| 24 | + body = regexp.MustCompile(`<updated>.*</updated>`).ReplaceAllString(body, "<updated></updated>") |
| 25 | + return body |
| 26 | + } |
| 27 | + t.Run("RSS feed", func(t *testing.T) { |
| 28 | + defer tests.PrintCurrentTest(t)() |
| 29 | + |
| 30 | + resp := MakeRequest(t, NewRequest(t, "GET", "/user2/repo1/releases.rss"), http.StatusOK) |
| 31 | + assert.EqualValues(t, `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> |
| 32 | + <channel> |
| 33 | + <title>Releases for user2/repo1</title> |
| 34 | + <link>http://localhost/user2/repo1/release</link> |
| 35 | + <description></description> |
| 36 | + <pubDate></pubDate> |
| 37 | + <item> |
| 38 | + <title>pre-release</title> |
| 39 | + <link>http://localhost/user2/repo1/releases/tag/v1.0</link> |
| 40 | + <description></description> |
| 41 | + <content:encoded><![CDATA[<p dir="auto">some text for a pre release</p> |
| 42 | +]]></content:encoded> |
| 43 | + <author>user2</author> |
| 44 | + <guid>5: http://localhost/user2/repo1/releases/tag/v1.0</guid> |
| 45 | + <pubDate></pubDate> |
| 46 | + </item> |
| 47 | + <item> |
| 48 | + <title>testing-release</title> |
| 49 | + <link>http://localhost/user2/repo1/releases/tag/v1.1</link> |
| 50 | + <description></description> |
| 51 | + <author>user2</author> |
| 52 | + <guid>1: http://localhost/user2/repo1/releases/tag/v1.1</guid> |
| 53 | + <pubDate></pubDate> |
| 54 | + </item> |
| 55 | + </channel> |
| 56 | +</rss>`, normalize(resp.Body.String())) |
| 57 | + }) |
| 58 | + |
| 59 | + t.Run("Atom feed", func(t *testing.T) { |
| 60 | + defer tests.PrintCurrentTest(t)() |
| 61 | + |
| 62 | + resp := MakeRequest(t, NewRequest(t, "GET", "/user2/repo1/releases.atom"), http.StatusOK) |
| 63 | + assert.EqualValues(t, `<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"> |
| 64 | + <title>Releases for user2/repo1</title> |
| 65 | + <id>http://localhost/user2/repo1/release</id> |
| 66 | + <updated></updated> |
| 67 | + <link href="http://localhost/user2/repo1/release"></link> |
| 68 | + <entry> |
| 69 | + <title>pre-release</title> |
| 70 | + <updated></updated> |
| 71 | + <id>5: http://localhost/user2/repo1/releases/tag/v1.0</id> |
| 72 | + <content type="html"><p dir="auto">some text for a pre release</p>
</content> |
| 73 | + <link href="http://localhost/user2/repo1/releases/tag/v1.0" rel="alternate"></link> |
| 74 | + <author> |
| 75 | + <name>user2</name> |
| 76 | + |
| 77 | + </author> |
| 78 | + </entry> |
| 79 | + <entry> |
| 80 | + <title>testing-release</title> |
| 81 | + <updated></updated> |
| 82 | + <id>1: http://localhost/user2/repo1/releases/tag/v1.1</id> |
| 83 | + <link href="http://localhost/user2/repo1/releases/tag/v1.1" rel="alternate"></link> |
| 84 | + <author> |
| 85 | + <name>user2</name> |
| 86 | + |
| 87 | + </author> |
| 88 | + </entry> |
| 89 | +</feed>`, normalize(resp.Body.String())) |
| 90 | + }) |
| 91 | +} |
0 commit comments