@@ -11,11 +11,11 @@ import (
1111	"testing" 
1212
1313	"code.gitea.io/gitea/models/issues" 
14- 	"code.gitea.io/gitea/models/unittest" 
15- 	"code.gitea.io/gitea/modules/git" 
16- 	"code.gitea.io/gitea/modules/log" 
14+ 	"code.gitea.io/gitea/models/repo" 
15+ 	user_model "code.gitea.io/gitea/models/user" 
1716	"code.gitea.io/gitea/modules/markup" 
1817	"code.gitea.io/gitea/modules/reqctx" 
18+ 	"code.gitea.io/gitea/modules/setting" 
1919	"code.gitea.io/gitea/modules/test" 
2020	"code.gitea.io/gitea/modules/translation" 
2121
4747	return  strings .ReplaceAll (s , "<SPACE>" , " " )
4848}
4949
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- 
5850func  TestMain (m  * testing.M ) {
59- 	unittest .InitSettingsForTesting ()
60- 	if  err  :=  git .InitSimple (context .Background ()); err  !=  nil  {
61- 		log .Fatal ("git init failed, err: %v" , err )
62- 	}
51+ 	setting .Markdown .RenderOptionsComment .ShortIssuePattern  =  true 
6352	markup .Init (& markup.RenderHelperFuncs {
6453		IsUsernameMentionable : func (ctx  context.Context , username  string ) bool  {
6554			return  username  ==  "mention-user" 
@@ -74,46 +63,52 @@ func newTestRenderUtils(t *testing.T) *RenderUtils {
7463	return  NewRenderUtils (ctx )
7564}
7665
77- func  TestRenderCommitBody (t  * testing.T ) {
78- 	defer  test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
79- 	type  args  struct  {
80- 		msg  string 
66+ func  TestRenderRepoComment (t  * testing.T ) {
67+ 	mockRepo  :=  & repo.Repository {
68+ 		ID : 1 , OwnerName : "user13" , Name : "repo11" ,
69+ 		Owner : & user_model.User {ID : 13 , Name : "user13" },
70+ 		Units : []* repo.RepoUnit {},
8171	}
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" ,
72+ 	t .Run ("RenderCommitBody" , func (t  * testing.T ) {
73+ 		defer  test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
74+ 		type  args  struct  {
75+ 			msg  string 
76+ 		}
77+ 		tests  :=  []struct  {
78+ 			name  string 
79+ 			args  args 
80+ 			want  template.HTML 
81+ 		}{
82+ 			{
83+ 				name : "multiple lines" ,
84+ 				args : args {
85+ 					msg : "first line\n second line" ,
86+ 				},
87+ 				want : "second line" ,
9188			},
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" ,
89+ 			{ 
90+ 				 name :  "multiple lines with leading newlines" ,
91+ 				 args :  args {
92+ 					 msg : "\n \n \n \n first line \n second line " ,
93+ 				}, 
94+ 				want : "second  line" ,
9895			},
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 " ,
96+ 			{ 
97+ 				 name :  "multiple lines with trailing newlines" ,
98+ 				 args :  args {
99+ 					 msg : "first line \n second line \n \n \n " ,
100+ 				}, 
101+ 				want : "second  line" ,
105102			},
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 
103+ 		}
104+ 		ut  :=  newTestRenderUtils (t )
105+ 		for  _ , tt  :=  range  tests  {
106+ 			t .Run (tt .name , func (t  * testing.T ) {
107+ 				assert .Equalf (t , tt .want , ut .RenderCommitBody (tt .args .msg , mockRepo ), "RenderCommitBody(%v, %v)" , tt .args .msg , nil )
108+ 			})
109+ 		}
110+ 
111+ 		expected  :=  `/just/a/path.bin 
117112<a href="https://example.com/file.bin">https://example.com/file.bin</a> 
118113[local link](file.bin) 
119114[remote link](<a href="https://example.com">https://example.com</a>) 
@@ -132,22 +127,22 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
132127<a href="/mention-user">@mention-user</a> test 
133128<a href="/user13/repo11/issues/123" class="ref-issue">#123</a> 
134129  space` 
135- 	assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderCommitBody (testInput (), testMetas )))
136- } 
130+ 		 assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderCommitBody (testInput (), mockRepo )))
131+ 	}) 
137132
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- } 
133+ 	 t . Run ( "RenderCommitMessage" ,  func (t  * testing.T ) {
134+ 		 expected  :=  `space <a href="/mention-user" data-markdown-generated-content="">@mention-user</a>  ` 
135+ 		 assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessage (testInput (), mockRepo ))
136+ 	}) 
142137
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- } 
138+ 	 t . Run ( "RenderCommitMessageLinkSubject" ,  func (t  * testing.T ) {
139+ 		 expected  :=  `<a href="https://example.com/link" class="muted">space </a><a href="/mention-user" data-markdown-generated-content="">@mention-user</a>` 
140+ 		 assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessageLinkSubject (testInput (), "https://example.com/link" , mockRepo ))
141+ 	}) 
147142
148- func   TestRenderIssueTitle (t  * testing.T ) {
149- 	defer  test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
150- 	expected  :=  `  space @mention-user<SPACE><SPACE> 
143+ 	 t . Run ( "RenderIssueTitle" ,  func (t  * testing.T ) {
144+ 		 defer  test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
145+ 		 expected  :=  `  space @mention-user<SPACE><SPACE> 
151146/just/a/path.bin 
152147https://example.com/file.bin 
153148[local link](file.bin) 
168163<a href="/user13/repo11/issues/123" class="ref-issue">#123</a> 
169164  space<SPACE><SPACE> 
170165` 
171- 	expected  =  strings .ReplaceAll (expected , "<SPACE>" , " " )
172- 	assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderIssueTitle (testInput (), testMetas )))
166+ 		expected  =  strings .ReplaceAll (expected , "<SPACE>" , " " )
167+ 		assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderIssueTitle (testInput (), mockRepo )))
168+ 	})
173169}
174170
175171func  TestRenderMarkdownToHtml (t  * testing.T ) {
0 commit comments