Merge pull request 'Port "Fix wrong test usage of AppSubURL"' (#2586) from gusted/forgejo-port-gt-29459 into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2586
Reviewed-by: Otto <otto@codeberg.org>
Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
This commit is contained in:
Gusted 2024-03-07 18:55:54 +00:00
commit 16cd8f9b8e
2 changed files with 27 additions and 34 deletions

View file

@ -24,11 +24,10 @@ import (
const ( const (
AppURL = "http://localhost:3000/" AppURL = "http://localhost:3000/"
Repo = "gogits/gogs" FullURL = AppURL + "gogits/gogs/"
AppSubURL = AppURL + Repo + "/"
) )
// these values should match the Repo const above // these values should match the const above
var localMetas = map[string]string{ var localMetas = map[string]string{
"user": "gogits", "user": "gogits",
"repo": "gogs", "repo": "gogs",
@ -50,13 +49,12 @@ func TestMain(m *testing.M) {
func TestRender_StandardLinks(t *testing.T) { func TestRender_StandardLinks(t *testing.T) {
setting.AppURL = AppURL setting.AppURL = AppURL
setting.AppSubURL = AppSubURL
test := func(input, expected, expectedWiki string) { test := func(input, expected, expectedWiki string) {
buffer, err := markdown.RenderString(&markup.RenderContext{ buffer, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext, Ctx: git.DefaultContext,
Links: markup.Links{ Links: markup.Links{
Base: setting.AppSubURL, Base: FullURL,
}, },
}, input) }, input)
assert.NoError(t, err) assert.NoError(t, err)
@ -65,7 +63,7 @@ func TestRender_StandardLinks(t *testing.T) {
buffer, err = markdown.RenderString(&markup.RenderContext{ buffer, err = markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext, Ctx: git.DefaultContext,
Links: markup.Links{ Links: markup.Links{
Base: setting.AppSubURL, Base: FullURL,
}, },
IsWiki: true, IsWiki: true,
}, input) }, input)
@ -76,8 +74,8 @@ func TestRender_StandardLinks(t *testing.T) {
googleRendered := `<p><a href="https://google.com/" rel="nofollow">https://google.com/</a></p>` googleRendered := `<p><a href="https://google.com/" rel="nofollow">https://google.com/</a></p>`
test("<https://google.com/>", googleRendered, googleRendered) test("<https://google.com/>", googleRendered, googleRendered)
lnk := util.URLJoin(AppSubURL, "WikiPage") lnk := util.URLJoin(FullURL, "WikiPage")
lnkWiki := util.URLJoin(AppSubURL, "wiki", "WikiPage") lnkWiki := util.URLJoin(FullURL, "wiki", "WikiPage")
test("[WikiPage](WikiPage)", test("[WikiPage](WikiPage)",
`<p><a href="`+lnk+`" rel="nofollow">WikiPage</a></p>`, `<p><a href="`+lnk+`" rel="nofollow">WikiPage</a></p>`,
`<p><a href="`+lnkWiki+`" rel="nofollow">WikiPage</a></p>`) `<p><a href="`+lnkWiki+`" rel="nofollow">WikiPage</a></p>`)
@ -85,13 +83,12 @@ func TestRender_StandardLinks(t *testing.T) {
func TestRender_Images(t *testing.T) { func TestRender_Images(t *testing.T) {
setting.AppURL = AppURL setting.AppURL = AppURL
setting.AppSubURL = AppSubURL
test := func(input, expected string) { test := func(input, expected string) {
buffer, err := markdown.RenderString(&markup.RenderContext{ buffer, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext, Ctx: git.DefaultContext,
Links: markup.Links{ Links: markup.Links{
Base: setting.AppSubURL, Base: FullURL,
}, },
}, input) }, input)
assert.NoError(t, err) assert.NoError(t, err)
@ -101,7 +98,7 @@ func TestRender_Images(t *testing.T) {
url := "../../.images/src/02/train.jpg" url := "../../.images/src/02/train.jpg"
title := "Train" title := "Train"
href := "https://gitea.io" href := "https://gitea.io"
result := util.URLJoin(AppSubURL, url) result := util.URLJoin(FullURL, url)
// hint: With Markdown v2.5.2, there is a new syntax: [link](URL){:target="_blank"} , but we do not support it now // hint: With Markdown v2.5.2, there is a new syntax: [link](URL){:target="_blank"} , but we do not support it now
test( test(
@ -291,15 +288,14 @@ This PR has been generated by [Renovate Bot](https://github.com/renovatebot/reno
func TestTotal_RenderWiki(t *testing.T) { func TestTotal_RenderWiki(t *testing.T) {
setting.AppURL = AppURL setting.AppURL = AppURL
setting.AppSubURL = AppSubURL
answers := testAnswers(util.URLJoin(AppSubURL, "wiki"), util.URLJoin(AppSubURL, "wiki", "raw")) answers := testAnswers(util.URLJoin(FullURL, "wiki"), util.URLJoin(FullURL, "wiki", "raw"))
for i := 0; i < len(sameCases); i++ { for i := 0; i < len(sameCases); i++ {
line, err := markdown.RenderString(&markup.RenderContext{ line, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext, Ctx: git.DefaultContext,
Links: markup.Links{ Links: markup.Links{
Base: setting.AppSubURL, Base: FullURL,
}, },
Metas: localMetas, Metas: localMetas,
IsWiki: true, IsWiki: true,
@ -312,12 +308,12 @@ func TestTotal_RenderWiki(t *testing.T) {
// Guard wiki sidebar: special syntax // Guard wiki sidebar: special syntax
`[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`,
// rendered // rendered
`<p><a href="` + AppSubURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p> `<p><a href="` + FullURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
`, `,
// special syntax // special syntax
`[[Name|Link]]`, `[[Name|Link]]`,
// rendered // rendered
`<p><a href="` + AppSubURL + `wiki/Link" rel="nofollow">Name</a></p> `<p><a href="` + FullURL + `wiki/Link" rel="nofollow">Name</a></p>
`, `,
} }
@ -325,7 +321,7 @@ func TestTotal_RenderWiki(t *testing.T) {
line, err := markdown.RenderString(&markup.RenderContext{ line, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext, Ctx: git.DefaultContext,
Links: markup.Links{ Links: markup.Links{
Base: setting.AppSubURL, Base: FullURL,
}, },
IsWiki: true, IsWiki: true,
}, testCases[i]) }, testCases[i])
@ -336,15 +332,14 @@ func TestTotal_RenderWiki(t *testing.T) {
func TestTotal_RenderString(t *testing.T) { func TestTotal_RenderString(t *testing.T) {
setting.AppURL = AppURL setting.AppURL = AppURL
setting.AppSubURL = AppSubURL
answers := testAnswers(util.URLJoin(AppSubURL, "src", "master"), util.URLJoin(AppSubURL, "media", "master")) answers := testAnswers(util.URLJoin(FullURL, "src", "master"), util.URLJoin(FullURL, "media", "master"))
for i := 0; i < len(sameCases); i++ { for i := 0; i < len(sameCases); i++ {
line, err := markdown.RenderString(&markup.RenderContext{ line, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext, Ctx: git.DefaultContext,
Links: markup.Links{ Links: markup.Links{
Base: AppSubURL, Base: FullURL,
BranchPath: "master", BranchPath: "master",
}, },
Metas: localMetas, Metas: localMetas,
@ -359,7 +354,7 @@ func TestTotal_RenderString(t *testing.T) {
line, err := markdown.RenderString(&markup.RenderContext{ line, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext, Ctx: git.DefaultContext,
Links: markup.Links{ Links: markup.Links{
Base: AppSubURL, Base: FullURL,
}, },
}, testCases[i]) }, testCases[i])
assert.NoError(t, err) assert.NoError(t, err)
@ -1176,15 +1171,13 @@ space</p>
func TestCustomMarkdownURL(t *testing.T) { func TestCustomMarkdownURL(t *testing.T) {
defer test.MockVariableValue(&setting.Markdown.CustomURLSchemes, []string{"abp"})() defer test.MockVariableValue(&setting.Markdown.CustomURLSchemes, []string{"abp"})()
setting.AppURL = AppURL setting.AppURL = AppURL
setting.AppSubURL = AppSubURL
test := func(input, expected string) { test := func(input, expected string) {
buffer, err := markdown.RenderString(&markup.RenderContext{ buffer, err := markdown.RenderString(&markup.RenderContext{
Ctx: git.DefaultContext, Ctx: git.DefaultContext,
Links: markup.Links{ Links: markup.Links{
Base: setting.AppSubURL, Base: FullURL,
BranchPath: "branch/main", BranchPath: "branch/main",
}, },
}, input) }, input)

View file

@ -22,7 +22,7 @@ import (
const ( const (
AppURL = "http://localhost:3000/" AppURL = "http://localhost:3000/"
Repo = "gogits/gogs" Repo = "gogits/gogs"
AppSubURL = AppURL + Repo + "/" FullURL = AppURL + Repo + "/"
) )
func testRenderMarkup(t *testing.T, mode, filePath, text, responseBody string, responseCode int) { func testRenderMarkup(t *testing.T, mode, filePath, text, responseBody string, responseCode int) {
@ -74,20 +74,20 @@ func TestAPI_RenderGFM(t *testing.T) {
// rendered // rendered
`<p>Wiki! Enjoy :)</p> `<p>Wiki! Enjoy :)</p>
<ul> <ul>
<li><a href="` + AppSubURL + `wiki/Links" rel="nofollow">Links, Language bindings, Engine bindings</a></li> <li><a href="` + FullURL + `wiki/Links" rel="nofollow">Links, Language bindings, Engine bindings</a></li>
<li><a href="` + AppSubURL + `wiki/Tips" rel="nofollow">Tips</a></li> <li><a href="` + FullURL + `wiki/Tips" rel="nofollow">Tips</a></li>
<li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="https://github.com/ocornut/imgui/issues/786" rel="nofollow">https://github.com/ocornut/imgui/issues/786</a></li> <li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="https://github.com/ocornut/imgui/issues/786" rel="nofollow">https://github.com/ocornut/imgui/issues/786</a></li>
</ul> </ul>
`, `,
// Guard wiki sidebar: special syntax // Guard wiki sidebar: special syntax
`[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`, `[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`,
// rendered // rendered
`<p><a href="` + AppSubURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p> `<p><a href="` + FullURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
`, `,
// special syntax // special syntax
`[[Name|Link]]`, `[[Name|Link]]`,
// rendered // rendered
`<p><a href="` + AppSubURL + `wiki/Link" rel="nofollow">Name</a></p> `<p><a href="` + FullURL + `wiki/Link" rel="nofollow">Name</a></p>
`, `,
// empty // empty
``, ``,
@ -111,8 +111,8 @@ Here are some links to the most important topics. You can find the full list of
<p><strong>Wine Staging</strong> on website <a href="http://wine-staging.com" rel="nofollow">wine-staging.com</a>.</p> <p><strong>Wine Staging</strong> on website <a href="http://wine-staging.com" rel="nofollow">wine-staging.com</a>.</p>
<h2 id="user-content-quick-links">Quick Links</h2> <h2 id="user-content-quick-links">Quick Links</h2>
<p>Here are some links to the most important topics. You can find the full list of pages at the sidebar.</p> <p>Here are some links to the most important topics. You can find the full list of pages at the sidebar.</p>
<p><a href="` + AppSubURL + `wiki/Configuration" rel="nofollow">Configuration</a> <p><a href="` + FullURL + `wiki/Configuration" rel="nofollow">Configuration</a>
<a href="` + AppSubURL + `wiki/raw/images/icon-bug.png" rel="nofollow"><img src="` + AppSubURL + `wiki/raw/images/icon-bug.png" title="icon-bug.png" alt="images/icon-bug.png"/></a></p> <a href="` + FullURL + `wiki/raw/images/icon-bug.png" rel="nofollow"><img src="` + FullURL + `wiki/raw/images/icon-bug.png" title="icon-bug.png" alt="images/icon-bug.png"/></a></p>
`, `,
} }