mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 00:11:04 +00:00 
			
		
		
		
	Resolves forgejo/forgejo#8793 ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [ ] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. ### Release notes - [ ] I do not want this change to show in the release notes. - [x] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. <!--start release-notes-assistant--> ## Release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Bug fixes - [PR](https://codeberg.org/forgejo/forgejo/pulls/8802): <!--number 8802 --><!--line 0 --><!--description Y29ycmVjdCByZWxlYXNlIGxpbmsgaW4gZmVlZA==-->correct release link in feed<!--description--> <!--end release-notes-assistant--> Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8802 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
		
			
				
	
	
		
			98 lines
		
	
	
	
		
			3.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			98 lines
		
	
	
	
		
			3.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
// Copyright 2025 The Forgejo Authors. All rights reserved.
 | 
						|
// SPDX-License-Identifier: GPL-3.0-or-later
 | 
						|
 | 
						|
package integration
 | 
						|
 | 
						|
import (
 | 
						|
	"fmt"
 | 
						|
	"net/http"
 | 
						|
	"regexp"
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"forgejo.org/tests"
 | 
						|
 | 
						|
	"github.com/stretchr/testify/assert"
 | 
						|
)
 | 
						|
 | 
						|
func TestReleaseFeed(t *testing.T) {
 | 
						|
	defer tests.PrepareTestEnv(t)()
 | 
						|
 | 
						|
	normalize := func(body string) string {
 | 
						|
		// Remove port.
 | 
						|
		body = regexp.MustCompile(`localhost:\d+`).ReplaceAllString(body, "localhost")
 | 
						|
		// date is timezone dependent.
 | 
						|
		body = regexp.MustCompile(`<pubDate>.*</pubDate>`).ReplaceAllString(body, "<pubDate></pubDate>")
 | 
						|
		body = regexp.MustCompile(`<updated>.*</updated>`).ReplaceAllString(body, "<updated></updated>")
 | 
						|
		return body
 | 
						|
	}
 | 
						|
	t.Run("RSS feed", func(t *testing.T) {
 | 
						|
		defer tests.PrintCurrentTest(t)()
 | 
						|
 | 
						|
		releasesPath := "/user2/repo1/releases"
 | 
						|
		MakeRequest(t, NewRequest(t, "GET", releasesPath), http.StatusOK)
 | 
						|
 | 
						|
		resp := MakeRequest(t, NewRequest(t, "GET", releasesPath+".rss"), http.StatusOK)
 | 
						|
		assert.Equal(t, fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
 | 
						|
  <channel>
 | 
						|
    <title>Releases for user2/repo1</title>
 | 
						|
    <link>http://localhost%[1]s</link>
 | 
						|
    <description></description>
 | 
						|
    <pubDate></pubDate>
 | 
						|
    <item>
 | 
						|
      <title>pre-release</title>
 | 
						|
      <link>http://localhost%[1]s/tag/v1.0</link>
 | 
						|
      <description></description>
 | 
						|
      <content:encoded><![CDATA[<p dir="auto">some text for a pre release</p>
 | 
						|
]]></content:encoded>
 | 
						|
      <author>user2</author>
 | 
						|
      <guid>5: http://localhost%[1]s/tag/v1.0</guid>
 | 
						|
      <pubDate></pubDate>
 | 
						|
    </item>
 | 
						|
    <item>
 | 
						|
      <title>testing-release</title>
 | 
						|
      <link>http://localhost%[1]s/tag/v1.1</link>
 | 
						|
      <description></description>
 | 
						|
      <author>user2</author>
 | 
						|
      <guid>1: http://localhost%[1]s/tag/v1.1</guid>
 | 
						|
      <pubDate></pubDate>
 | 
						|
    </item>
 | 
						|
  </channel>
 | 
						|
</rss>`, releasesPath), normalize(resp.Body.String()))
 | 
						|
	})
 | 
						|
 | 
						|
	t.Run("Atom feed", func(t *testing.T) {
 | 
						|
		defer tests.PrintCurrentTest(t)()
 | 
						|
 | 
						|
		releasesPath := "/user2/repo1/releases"
 | 
						|
		MakeRequest(t, NewRequest(t, "GET", releasesPath), http.StatusOK)
 | 
						|
 | 
						|
		resp := MakeRequest(t, NewRequest(t, "GET", releasesPath+".atom"), http.StatusOK)
 | 
						|
		assert.Equal(t, fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom">
 | 
						|
  <title>Releases for user2/repo1</title>
 | 
						|
  <id>http://localhost%[1]s</id>
 | 
						|
  <updated></updated>
 | 
						|
  <link href="http://localhost%[1]s"></link>
 | 
						|
  <entry>
 | 
						|
    <title>pre-release</title>
 | 
						|
    <updated></updated>
 | 
						|
    <id>5: http://localhost%[1]s/tag/v1.0</id>
 | 
						|
    <content type="html"><p dir="auto">some text for a pre release</p>
</content>
 | 
						|
    <link href="http://localhost%[1]s/tag/v1.0" rel="alternate"></link>
 | 
						|
    <author>
 | 
						|
      <name>user2</name>
 | 
						|
      <email>user2@noreply.example.org</email>
 | 
						|
    </author>
 | 
						|
  </entry>
 | 
						|
  <entry>
 | 
						|
    <title>testing-release</title>
 | 
						|
    <updated></updated>
 | 
						|
    <id>1: http://localhost%[1]s/tag/v1.1</id>
 | 
						|
    <link href="http://localhost%[1]s/tag/v1.1" rel="alternate"></link>
 | 
						|
    <author>
 | 
						|
      <name>user2</name>
 | 
						|
      <email>user2@noreply.example.org</email>
 | 
						|
    </author>
 | 
						|
  </entry>
 | 
						|
</feed>`, releasesPath), normalize(resp.Body.String()))
 | 
						|
	})
 | 
						|
}
 |