@@ -11,7 +11,9 @@ import (
1111 "testing"
1212
1313 "code.gitea.io/gitea/models/issues"
14+ "code.gitea.io/gitea/models/repo"
1415 "code.gitea.io/gitea/models/unittest"
16+ user_model "code.gitea.io/gitea/models/user"
1517 "code.gitea.io/gitea/modules/git"
1618 "code.gitea.io/gitea/modules/log"
1719 "code.gitea.io/gitea/modules/markup"
4749 return strings .ReplaceAll (s , "<SPACE>" , " " )
4850}
4951
50- var testMetas = map [string ]string {
51- "user" : "user13" ,
52- "repo" : "repo11" ,
53- "repoPath" : "../../tests/gitea-repositories-meta/user13/repo11.git/" ,
54- "markdownNewLineHardBreak" : "true" ,
55- "markupAllowShortIssuePattern" : "true" ,
56- }
57-
5852func TestMain (m * testing.M ) {
5953 unittest .InitSettingsForTesting ()
6054 if err := git .InitSimple (context .Background ()); err != nil {
@@ -74,46 +68,52 @@ func newTestRenderUtils(t *testing.T) *RenderUtils {
7468 return NewRenderUtils (ctx )
7569}
7670
77- func TestRenderCommitBody (t * testing.T ) {
78- defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
79- type args struct {
80- msg string
71+ func TestRenderRepoComment (t * testing.T ) {
72+ mockRepo := & repo.Repository {
73+ ID : 1 , OwnerName : "user13" , Name : "repo11" ,
74+ Owner : & user_model.User {ID : 13 , Name : "user13" },
75+ Units : []* repo.RepoUnit {},
8176 }
82- tests := []struct {
83- name string
84- args args
85- want template.HTML
86- }{
87- {
88- name : "multiple lines" ,
89- args : args {
90- msg : "first line\n second line" ,
77+ t .Run ("RenderCommitBody" , func (t * testing.T ) {
78+ defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
79+ type args struct {
80+ msg string
81+ }
82+ tests := []struct {
83+ name string
84+ args args
85+ want template.HTML
86+ }{
87+ {
88+ name : "multiple lines" ,
89+ args : args {
90+ msg : "first line\n second line" ,
91+ },
92+ want : "second line" ,
9193 },
92- want : "second line" ,
93- } ,
94- {
95- name : "multiple lines with leading newlines " ,
96- args : args {
97- msg : "\n \n \n \n first line \n second line" ,
94+ {
95+ name : "multiple lines with leading newlines" ,
96+ args : args {
97+ msg : "\n \n \n \n first line \n second line " ,
98+ },
99+ want : "second line" ,
98100 },
99- want : "second line" ,
100- } ,
101- {
102- name : "multiple lines with trailing newlines " ,
103- args : args {
104- msg : "first line\n second line \n \n \n " ,
101+ {
102+ name : "multiple lines with trailing newlines" ,
103+ args : args {
104+ msg : "first line \n second line \n \n \n " ,
105+ },
106+ want : "second line" ,
105107 },
106- want : "second line" ,
107- },
108- }
109- ut := newTestRenderUtils (t )
110- for _ , tt := range tests {
111- t .Run (tt .name , func (t * testing.T ) {
112- assert .Equalf (t , tt .want , ut .RenderCommitBody (tt .args .msg , nil ), "RenderCommitBody(%v, %v)" , tt .args .msg , nil )
113- })
114- }
115-
116- expected := `/just/a/path.bin
108+ }
109+ ut := newTestRenderUtils (t )
110+ for _ , tt := range tests {
111+ t .Run (tt .name , func (t * testing.T ) {
112+ assert .Equalf (t , tt .want , ut .RenderCommitBody (tt .args .msg , mockRepo ), "RenderCommitBody(%v, %v)" , tt .args .msg , nil )
113+ })
114+ }
115+
116+ expected := `/just/a/path.bin
117117<a href="https://example.com/file.bin">https://example.com/file.bin</a>
118118[local link](file.bin)
119119[remote link](<a href="https://example.com">https://example.com</a>)
@@ -132,22 +132,22 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
132132<a href="/mention-user">@mention-user</a> test
133133<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
134134 space`
135- assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderCommitBody (testInput (), testMetas )))
136- }
135+ assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderCommitBody (testInput (), mockRepo )))
136+ })
137137
138- func TestRenderCommitMessage (t * testing.T ) {
139- expected := `space <a href="/mention-user" data-markdown-generated-content="">@mention-user</a> `
140- assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessage (testInput (), testMetas ))
141- }
138+ t . Run ( "RenderCommitMessage" , func (t * testing.T ) {
139+ expected := `space <a href="/mention-user" data-markdown-generated-content="">@mention-user</a> `
140+ assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessage (testInput (), mockRepo ))
141+ })
142142
143- func TestRenderCommitMessageLinkSubject (t * testing.T ) {
144- expected := `<a href="https://example.com/link" class="muted">space </a><a href="/mention-user" data-markdown-generated-content="">@mention-user</a>`
145- assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessageLinkSubject (testInput (), "https://example.com/link" , testMetas ))
146- }
143+ t . Run ( "RenderCommitMessageLinkSubject" , func (t * testing.T ) {
144+ expected := `<a href="https://example.com/link" class="muted">space </a><a href="/mention-user" data-markdown-generated-content="">@mention-user</a>`
145+ assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessageLinkSubject (testInput (), "https://example.com/link" , mockRepo ))
146+ })
147147
148- func TestRenderIssueTitle (t * testing.T ) {
149- defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
150- expected := ` space @mention-user<SPACE><SPACE>
148+ t . Run ( "RenderIssueTitle" , func (t * testing.T ) {
149+ defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
150+ expected := ` space @mention-user<SPACE><SPACE>
151151/just/a/path.bin
152152https://example.com/file.bin
153153[local link](file.bin)
168168<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
169169 space<SPACE><SPACE>
170170`
171- expected = strings .ReplaceAll (expected , "<SPACE>" , " " )
172- assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderIssueTitle (testInput (), testMetas )))
171+ expected = strings .ReplaceAll (expected , "<SPACE>" , " " )
172+ assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderIssueTitle (testInput (), mockRepo )))
173+ })
173174}
174175
175176func TestRenderMarkdownToHtml (t * testing.T ) {
0 commit comments