@@ -11,7 +11,9 @@ import (
11
11
"testing"
12
12
13
13
"code.gitea.io/gitea/models/issues"
14
+ "code.gitea.io/gitea/models/repo"
14
15
"code.gitea.io/gitea/models/unittest"
16
+ user_model "code.gitea.io/gitea/models/user"
15
17
"code.gitea.io/gitea/modules/git"
16
18
"code.gitea.io/gitea/modules/log"
17
19
"code.gitea.io/gitea/modules/markup"
48
50
}
49
51
50
52
var testMetas = map [string ]string {
51
- "user" : "user13" ,
52
- "repo" : "repo11" ,
53
53
"repoPath" : "../../tests/gitea-repositories-meta/user13/repo11.git/" ,
54
54
"markdownNewLineHardBreak" : "true" ,
55
55
"markupAllowShortIssuePattern" : "true" ,
@@ -74,46 +74,52 @@ func newTestRenderUtils(t *testing.T) *RenderUtils {
74
74
return NewRenderUtils (ctx )
75
75
}
76
76
77
- func TestRenderCommitBody (t * testing.T ) {
78
- defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
79
- type args struct {
80
- msg string
77
+ func TestRenderRepoComment (t * testing.T ) {
78
+ mockRepo := & repo.Repository {
79
+ ID : 1 , OwnerName : "user13" , Name : "repo11" ,
80
+ Owner : & user_model.User {ID : 13 , Name : "user13" },
81
+ Units : []* repo.RepoUnit {},
81
82
}
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" ,
83
+ t .Run ("RenderCommitBody" , func (t * testing.T ) {
84
+ defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
85
+ type args struct {
86
+ msg string
87
+ }
88
+ tests := []struct {
89
+ name string
90
+ args args
91
+ want template.HTML
92
+ }{
93
+ {
94
+ name : "multiple lines" ,
95
+ args : args {
96
+ msg : "first line\n second line" ,
97
+ },
98
+ want : "second line" ,
91
99
},
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" ,
100
+ {
101
+ name : "multiple lines with leading newlines" ,
102
+ args : args {
103
+ msg : "\n \n \n \n first line \n second line " ,
104
+ },
105
+ want : "second line" ,
98
106
},
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 " ,
107
+ {
108
+ name : "multiple lines with trailing newlines" ,
109
+ args : args {
110
+ msg : "first line \n second line \n \n \n " ,
111
+ },
112
+ want : "second line" ,
105
113
},
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
114
+ }
115
+ ut := newTestRenderUtils (t )
116
+ for _ , tt := range tests {
117
+ t .Run (tt .name , func (t * testing.T ) {
118
+ assert .Equalf (t , tt .want , ut .RenderCommitBody (tt .args .msg , mockRepo ), "RenderCommitBody(%v, %v)" , tt .args .msg , nil )
119
+ })
120
+ }
121
+
122
+ expected := `/just/a/path.bin
117
123
<a href="https://example.com/file.bin">https://example.com/file.bin</a>
118
124
[local link](file.bin)
119
125
[remote link](<a href="https://example.com">https://example.com</a>)
@@ -132,22 +138,22 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
132
138
<a href="/mention-user">@mention-user</a> test
133
139
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
134
140
space`
135
- assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderCommitBody (testInput (), testMetas )))
136
- }
141
+ assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderCommitBody (testInput (), mockRepo )))
142
+ })
137
143
138
- func TestRenderCommitMessage (t * testing.T ) {
139
- expected := `space <a href="https://github.com/mention-user" data-markdown-generated-content="">@mention-user</a> `
140
- assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessage (testInput (), testMetas ))
141
- }
144
+ t . Run ( "RenderCommitMessage" , func (t * testing.T ) {
145
+ expected := `space <a href="https://github.com/mention-user" data-markdown-generated-content="">@mention-user</a> `
146
+ assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessage (testInput (), mockRepo ))
147
+ })
142
148
143
- func TestRenderCommitMessageLinkSubject (t * testing.T ) {
144
- expected := `<a href="https://example.com/link" class="muted">space </a><a href="https://github.com/mention-user" data-markdown-generated-content="">@mention-user</a>`
145
- assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessageLinkSubject (testInput (), "https://example.com/link" , testMetas ))
146
- }
149
+ t . Run ( "RenderCommitMessageLinkSubject" , func (t * testing.T ) {
150
+ expected := `<a href="https://example.com/link" class="muted">space </a><a href="https://github.com/mention-user" data-markdown-generated-content="">@mention-user</a>`
151
+ assert .EqualValues (t , expected , newTestRenderUtils (t ).RenderCommitMessageLinkSubject (testInput (), "https://example.com/link" , mockRepo ))
152
+ })
147
153
148
- func TestRenderIssueTitle (t * testing.T ) {
149
- defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
150
- expected := ` space @mention-user<SPACE><SPACE>
154
+ t . Run ( "RenderIssueTitle" , func (t * testing.T ) {
155
+ defer test .MockVariableValue (& markup .RenderBehaviorForTesting .DisableAdditionalAttributes , true )()
156
+ expected := ` space @mention-user<SPACE><SPACE>
151
157
/just/a/path.bin
152
158
https://example.com/file.bin
153
159
[local link](file.bin)
168
174
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
169
175
space<SPACE><SPACE>
170
176
`
171
- expected = strings .ReplaceAll (expected , "<SPACE>" , " " )
172
- assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderIssueTitle (testInput (), testMetas )))
177
+ expected = strings .ReplaceAll (expected , "<SPACE>" , " " )
178
+ assert .Equal (t , expected , string (newTestRenderUtils (t ).RenderIssueTitle (testInput (), mockRepo )))
179
+ })
173
180
}
174
181
175
182
func TestRenderMarkdownToHtml (t * testing.T ) {
0 commit comments