@@ -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"
47
49
return strings .ReplaceAll (s , "<SPACE>" , " " )
48
50
}
49
51
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
-
58
52
func TestMain (m * testing.M ) {
59
53
unittest .InitSettingsForTesting ()
60
54
if err := git .InitSimple (context .Background ()); err != nil {
@@ -74,46 +68,52 @@ func newTestRenderUtils(t *testing.T) *RenderUtils {
74
68
return NewRenderUtils (ctx )
75
69
}
76
70
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 {},
81
76
}
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" ,
91
93
},
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" ,
98
100
},
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" ,
105
107
},
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
117
117
<a href="https://example.com/file.bin">https://example.com/file.bin</a>
118
118
[local link](file.bin)
119
119
[remote link](<a href="https://example.com">https://example.com</a>)
@@ -132,22 +132,22 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
132
132
<a href="/mention-user">@mention-user</a> test
133
133
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
134
134
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
+ })
137
137
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
- }
138
+ t . Run ( "RenderCommitMessage" , func (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 (), mockRepo ))
141
+ })
142
142
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
- }
143
+ t . Run ( "RenderCommitMessageLinkSubject" , func (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" , mockRepo ))
146
+ })
147
147
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>
151
151
/just/a/path.bin
152
152
https://example.com/file.bin
153
153
[local link](file.bin)
168
168
<a href="/user13/repo11/issues/123" class="ref-issue">#123</a>
169
169
space<SPACE><SPACE>
170
170
`
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
+ })
173
174
}
174
175
175
176
func TestRenderMarkdownToHtml (t * testing.T ) {
0 commit comments