@@ -6,12 +6,11 @@ package markdown_test
66import (
77 "context"
88 "html/template"
9- "os"
109 "strings"
1110 "testing"
1211
13- "code.gitea.io/gitea/models/unittest"
1412 "code.gitea.io/gitea/modules/git"
13+ "code.gitea.io/gitea/modules/gitrepo"
1514 "code.gitea.io/gitea/modules/log"
1615 "code.gitea.io/gitea/modules/markup"
1716 "code.gitea.io/gitea/modules/markup/markdown"
@@ -25,28 +24,36 @@ import (
2524)
2625
2726const (
28- AppURL = "http://localhost:3000/"
29- FullURL = AppURL + "gogits/gogs/"
27+ AppURL = "http://localhost:3000/"
28+ testRepoOwnerName = "user13"
29+ testRepoName = "repo11"
30+ FullURL = AppURL + testRepoOwnerName + "/" + testRepoName + "/"
3031)
3132
3233// these values should match the const above
3334var localMetas = map [string ]string {
34- "user" : "gogits" ,
35- "repo" : "gogs" ,
36- "repoPath" : "../../../tests/gitea-repositories-meta/user13/repo11.git/" ,
35+ "user" : testRepoOwnerName ,
36+ "repo" : testRepoName ,
3737}
3838
39- func TestMain (m * testing.M ) {
40- unittest .InitSettings ()
41- if err := git .InitSimple (context .Background ()); err != nil {
42- log .Fatal ("git init failed, err: %v" , err )
39+ type mockRepo struct {
40+ OwnerName string
41+ RepoName string
42+ }
43+
44+ func (m * mockRepo ) GetOwnerName () string {
45+ return m .OwnerName
46+ }
47+
48+ func (m * mockRepo ) GetName () string {
49+ return m .RepoName
50+ }
51+
52+ func newMockRepo (ownerName , repoName string ) gitrepo.Repository {
53+ return & mockRepo {
54+ OwnerName : ownerName ,
55+ RepoName : repoName ,
4356 }
44- markup .Init (& markup.ProcessorHelper {
45- IsUsernameMentionable : func (ctx context.Context , username string ) bool {
46- return username == "r-lyeh"
47- },
48- })
49- os .Exit (m .Run ())
5057}
5158
5259func TestRender_StandardLinks (t * testing.T ) {
@@ -133,11 +140,11 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
133140<li><a href="` + baseURLContent + `/Links" rel="nofollow">Links, Language bindings, Engine bindings</a></li>
134141<li><a href="` + baseURLContent + `/Tips" rel="nofollow">Tips</a></li>
135142</ul>
136- <p>See commit <a href="/gogits/gogs /commit/65f1bf27bc" rel="nofollow"><code>65f1bf27bc</code></a></p>
143+ <p>See commit <a href="/` + testRepoOwnerName + `/` + testRepoName + ` /commit/65f1bf27bc" rel="nofollow"><code>65f1bf27bc</code></a></p>
137144<p>Ideas and codes</p>
138145<ul>
139146<li>Bezier widget (by <a href="/r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/ocornut/imgui/issues/786" class="ref-issue" rel="nofollow">ocornut/imgui#786</a></li>
140- <li>Bezier widget (by <a href="/r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/gogits/gogs/ issues/786" class="ref-issue" rel="nofollow">#786</a></li>
147+ <li>Bezier widget (by <a href="/r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="` + FullURL + ` issues/786" class="ref-issue" rel="nofollow">#786</a></li>
141148<li>Node graph editors <a href="https://github.com/ocornut/imgui/issues/306" rel="nofollow">https://github.com/ocornut/imgui/issues/306</a></li>
142149<li><a href="` + baseURLContent + `/memory_editor_example" rel="nofollow">Memory Editor</a></li>
143150<li><a href="` + baseURLContent + `/plot_var_example" rel="nofollow">Plot var helper</a></li>
@@ -222,7 +229,7 @@ See commit 65f1bf27bc
222229Ideas and codes
223230
224231- Bezier widget (by @r-lyeh) ` + AppURL + `ocornut/imgui/issues/786
225- - Bezier widget (by @r-lyeh) ` + AppURL + `gogits/gogs/ issues/786
232+ - Bezier widget (by @r-lyeh) ` + FullURL + `issues/786
226233- Node graph editors https://github.com/ocornut/imgui/issues/306
227234- [[Memory Editor|memory_editor_example]]
228235- [[Plot var helper|plot_var_example]]` ,
@@ -299,6 +306,7 @@ func TestTotal_RenderWiki(t *testing.T) {
299306 Links : markup.Links {
300307 Base : FullURL ,
301308 },
309+ Repo : newMockRepo (testRepoOwnerName , testRepoName ),
302310 Metas : localMetas ,
303311 IsWiki : true ,
304312 }, sameCases [i ])
@@ -344,6 +352,7 @@ func TestTotal_RenderString(t *testing.T) {
344352 Base : FullURL ,
345353 BranchPath : "master" ,
346354 },
355+ Repo : newMockRepo (testRepoOwnerName , testRepoName ),
347356 Metas : localMetas ,
348357 }, sameCases [i ])
349358 assert .NoError (t , err )
0 commit comments