Skip to content

Commit 90549e3

Browse files
KN4CK3RGiteaBot
authored andcommittedFeb 29, 2024
Fix wrong test usage of AppSubURL (go-gitea#29459)
The tests use an invalid `setting.AppSubURL`. The wrong behaviour disturbs other PRs like go-gitea#29222 and go-gitea#29427.
1 parent 9abba8c commit 90549e3

File tree

2 files changed

+26
-31
lines changed

2 files changed

+26
-31
lines changed
 

‎modules/markup/markdown/markdown_test.go

+17-22
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ import (
2121
)
2222

2323
const (
24-
AppURL = "http://localhost:3000/"
25-
Repo = "gogits/gogs"
26-
AppSubURL = AppURL + Repo + "/"
24+
AppURL = "http://localhost:3000/"
25+
FullURL = AppURL + "gogits/gogs/"
2726
)
2827

29-
// these values should match the Repo const above
28+
// these values should match the const above
3029
var localMetas = map[string]string{
3130
"user": "gogits",
3231
"repo": "gogs",
@@ -48,13 +47,12 @@ func TestMain(m *testing.M) {
4847

4948
func TestRender_StandardLinks(t *testing.T) {
5049
setting.AppURL = AppURL
51-
setting.AppSubURL = AppSubURL
5250

5351
test := func(input, expected, expectedWiki string) {
5452
buffer, err := RenderString(&markup.RenderContext{
5553
Ctx: git.DefaultContext,
5654
Links: markup.Links{
57-
Base: setting.AppSubURL,
55+
Base: FullURL,
5856
},
5957
}, input)
6058
assert.NoError(t, err)
@@ -63,7 +61,7 @@ func TestRender_StandardLinks(t *testing.T) {
6361
buffer, err = RenderString(&markup.RenderContext{
6462
Ctx: git.DefaultContext,
6563
Links: markup.Links{
66-
Base: setting.AppSubURL,
64+
Base: FullURL,
6765
},
6866
IsWiki: true,
6967
}, input)
@@ -74,22 +72,21 @@ func TestRender_StandardLinks(t *testing.T) {
7472
googleRendered := `<p><a href="https://google.com/" rel="nofollow">https://google.com/</a></p>`
7573
test("<https://google.com/>", googleRendered, googleRendered)
7674

77-
lnk := util.URLJoin(AppSubURL, "WikiPage")
78-
lnkWiki := util.URLJoin(AppSubURL, "wiki", "WikiPage")
75+
lnk := util.URLJoin(FullURL, "WikiPage")
76+
lnkWiki := util.URLJoin(FullURL, "wiki", "WikiPage")
7977
test("[WikiPage](WikiPage)",
8078
`<p><a href="`+lnk+`" rel="nofollow">WikiPage</a></p>`,
8179
`<p><a href="`+lnkWiki+`" rel="nofollow">WikiPage</a></p>`)
8280
}
8381

8482
func TestRender_Images(t *testing.T) {
8583
setting.AppURL = AppURL
86-
setting.AppSubURL = AppSubURL
8784

8885
test := func(input, expected string) {
8986
buffer, err := RenderString(&markup.RenderContext{
9087
Ctx: git.DefaultContext,
9188
Links: markup.Links{
92-
Base: setting.AppSubURL,
89+
Base: FullURL,
9390
},
9491
}, input)
9592
assert.NoError(t, err)
@@ -99,7 +96,7 @@ func TestRender_Images(t *testing.T) {
9996
url := "../../.images/src/02/train.jpg"
10097
title := "Train"
10198
href := "https://gitea.io"
102-
result := util.URLJoin(AppSubURL, url)
99+
result := util.URLJoin(FullURL, url)
103100
// hint: With Markdown v2.5.2, there is a new syntax: [link](URL){:target="_blank"} , but we do not support it now
104101

105102
test(
@@ -289,15 +286,14 @@ This PR has been generated by [Renovate Bot](https://github.com/renovatebot/reno
289286

290287
func TestTotal_RenderWiki(t *testing.T) {
291288
setting.AppURL = AppURL
292-
setting.AppSubURL = AppSubURL
293289

294-
answers := testAnswers(util.URLJoin(AppSubURL, "wiki"), util.URLJoin(AppSubURL, "wiki", "raw"))
290+
answers := testAnswers(util.URLJoin(FullURL, "wiki"), util.URLJoin(FullURL, "wiki", "raw"))
295291

296292
for i := 0; i < len(sameCases); i++ {
297293
line, err := RenderString(&markup.RenderContext{
298294
Ctx: git.DefaultContext,
299295
Links: markup.Links{
300-
Base: setting.AppSubURL,
296+
Base: FullURL,
301297
},
302298
Metas: localMetas,
303299
IsWiki: true,
@@ -310,20 +306,20 @@ func TestTotal_RenderWiki(t *testing.T) {
310306
// Guard wiki sidebar: special syntax
311307
`[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`,
312308
// rendered
313-
`<p><a href="` + AppSubURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
309+
`<p><a href="` + FullURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
314310
`,
315311
// special syntax
316312
`[[Name|Link]]`,
317313
// rendered
318-
`<p><a href="` + AppSubURL + `wiki/Link" rel="nofollow">Name</a></p>
314+
`<p><a href="` + FullURL + `wiki/Link" rel="nofollow">Name</a></p>
319315
`,
320316
}
321317

322318
for i := 0; i < len(testCases); i += 2 {
323319
line, err := RenderString(&markup.RenderContext{
324320
Ctx: git.DefaultContext,
325321
Links: markup.Links{
326-
Base: setting.AppSubURL,
322+
Base: FullURL,
327323
},
328324
IsWiki: true,
329325
}, testCases[i])
@@ -334,15 +330,14 @@ func TestTotal_RenderWiki(t *testing.T) {
334330

335331
func TestTotal_RenderString(t *testing.T) {
336332
setting.AppURL = AppURL
337-
setting.AppSubURL = AppSubURL
338333

339-
answers := testAnswers(util.URLJoin(AppSubURL, "src", "master"), util.URLJoin(AppSubURL, "media", "master"))
334+
answers := testAnswers(util.URLJoin(FullURL, "src", "master"), util.URLJoin(FullURL, "media", "master"))
340335

341336
for i := 0; i < len(sameCases); i++ {
342337
line, err := RenderString(&markup.RenderContext{
343338
Ctx: git.DefaultContext,
344339
Links: markup.Links{
345-
Base: AppSubURL,
340+
Base: FullURL,
346341
BranchPath: "master",
347342
},
348343
Metas: localMetas,
@@ -357,7 +352,7 @@ func TestTotal_RenderString(t *testing.T) {
357352
line, err := RenderString(&markup.RenderContext{
358353
Ctx: git.DefaultContext,
359354
Links: markup.Links{
360-
Base: AppSubURL,
355+
Base: FullURL,
361356
},
362357
}, testCases[i])
363358
assert.NoError(t, err)

‎routers/api/v1/misc/markup_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
)
2121

2222
const (
23-
AppURL = "http://localhost:3000/"
24-
Repo = "gogits/gogs"
25-
AppSubURL = AppURL + Repo + "/"
23+
AppURL = "http://localhost:3000/"
24+
Repo = "gogits/gogs"
25+
FullURL = AppURL + Repo + "/"
2626
)
2727

2828
func testRenderMarkup(t *testing.T, mode, filePath, text, responseBody string, responseCode int) {
@@ -74,20 +74,20 @@ func TestAPI_RenderGFM(t *testing.T) {
7474
// rendered
7575
`<p>Wiki! Enjoy :)</p>
7676
<ul>
77-
<li><a href="` + AppSubURL + `wiki/Links" rel="nofollow">Links, Language bindings, Engine bindings</a></li>
78-
<li><a href="` + AppSubURL + `wiki/Tips" rel="nofollow">Tips</a></li>
77+
<li><a href="` + FullURL + `wiki/Links" rel="nofollow">Links, Language bindings, Engine bindings</a></li>
78+
<li><a href="` + FullURL + `wiki/Tips" rel="nofollow">Tips</a></li>
7979
<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>
8080
</ul>
8181
`,
8282
// Guard wiki sidebar: special syntax
8383
`[[Guardfile-DSL / Configuring-Guard|Guardfile-DSL---Configuring-Guard]]`,
8484
// rendered
85-
`<p><a href="` + AppSubURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
85+
`<p><a href="` + FullURL + `wiki/Guardfile-DSL---Configuring-Guard" rel="nofollow">Guardfile-DSL / Configuring-Guard</a></p>
8686
`,
8787
// special syntax
8888
`[[Name|Link]]`,
8989
// rendered
90-
`<p><a href="` + AppSubURL + `wiki/Link" rel="nofollow">Name</a></p>
90+
`<p><a href="` + FullURL + `wiki/Link" rel="nofollow">Name</a></p>
9191
`,
9292
// empty
9393
``,
@@ -111,8 +111,8 @@ Here are some links to the most important topics. You can find the full list of
111111
<p><strong>Wine Staging</strong> on website <a href="http://wine-staging.com" rel="nofollow">wine-staging.com</a>.</p>
112112
<h2 id="user-content-quick-links">Quick Links</h2>
113113
<p>Here are some links to the most important topics. You can find the full list of pages at the sidebar.</p>
114-
<p><a href="` + AppSubURL + `wiki/Configuration" rel="nofollow">Configuration</a>
115-
<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>
114+
<p><a href="` + FullURL + `wiki/Configuration" rel="nofollow">Configuration</a>
115+
<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>
116116
`,
117117
}
118118

0 commit comments

Comments
 (0)
Please sign in to comment.