@@ -6,12 +6,11 @@ package markdown_test
6
6
import (
7
7
"context"
8
8
"html/template"
9
- "os"
10
9
"strings"
11
10
"testing"
12
11
13
- "code.gitea.io/gitea/models/unittest"
14
12
"code.gitea.io/gitea/modules/git"
13
+ "code.gitea.io/gitea/modules/gitrepo"
15
14
"code.gitea.io/gitea/modules/log"
16
15
"code.gitea.io/gitea/modules/markup"
17
16
"code.gitea.io/gitea/modules/markup/markdown"
@@ -25,28 +24,36 @@ import (
25
24
)
26
25
27
26
const (
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 + "/"
30
31
)
31
32
32
33
// these values should match the const above
33
34
var 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 ,
37
37
}
38
38
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 ,
43
56
}
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 ())
50
57
}
51
58
52
59
func TestRender_StandardLinks (t * testing.T ) {
@@ -133,11 +140,11 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
133
140
<li><a href="` + baseURLContent + `/Links" rel="nofollow">Links, Language bindings, Engine bindings</a></li>
134
141
<li><a href="` + baseURLContent + `/Tips" rel="nofollow">Tips</a></li>
135
142
</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>
137
144
<p>Ideas and codes</p>
138
145
<ul>
139
146
<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>
141
148
<li>Node graph editors <a href="https://github.com/ocornut/imgui/issues/306" rel="nofollow">https://github.com/ocornut/imgui/issues/306</a></li>
142
149
<li><a href="` + baseURLContent + `/memory_editor_example" rel="nofollow">Memory Editor</a></li>
143
150
<li><a href="` + baseURLContent + `/plot_var_example" rel="nofollow">Plot var helper</a></li>
@@ -222,7 +229,7 @@ See commit 65f1bf27bc
222
229
Ideas and codes
223
230
224
231
- 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
226
233
- Node graph editors https://github.com/ocornut/imgui/issues/306
227
234
- [[Memory Editor|memory_editor_example]]
228
235
- [[Plot var helper|plot_var_example]]` ,
@@ -299,6 +306,7 @@ func TestTotal_RenderWiki(t *testing.T) {
299
306
Links : markup.Links {
300
307
Base : FullURL ,
301
308
},
309
+ Repo : newMockRepo (testRepoOwnerName , testRepoName ),
302
310
Metas : localMetas ,
303
311
IsWiki : true ,
304
312
}, sameCases [i ])
@@ -344,6 +352,7 @@ func TestTotal_RenderString(t *testing.T) {
344
352
Base : FullURL ,
345
353
BranchPath : "master" ,
346
354
},
355
+ Repo : newMockRepo (testRepoOwnerName , testRepoName ),
347
356
Metas : localMetas ,
348
357
}, sameCases [i ])
349
358
assert .NoError (t , err )
0 commit comments