File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -210,3 +210,53 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
210
210
_ , err = masterTree .GetTreeEntryByPath (wikiPath )
211
211
assert .Error (t , err )
212
212
}
213
+
214
+ func TestPrepareWikiFileName (t * testing.T ) {
215
+ models .PrepareTestEnv (t )
216
+ repo := models .AssertExistsAndLoadBean (t , & models.Repository {ID : 1 }).(* models.Repository )
217
+ gitRepo , err := git .OpenRepository (repo .WikiPath ())
218
+ assert .NoError (t , err )
219
+
220
+ tests := []struct {
221
+ name string
222
+ arg string
223
+ hasWiki bool
224
+ wikiPath string
225
+ wantErr bool
226
+ }{{
227
+ name : "add suffix" ,
228
+ arg : "home" ,
229
+ hasWiki : true ,
230
+ wikiPath : "home.md" ,
231
+ wantErr : false ,
232
+ }, {
233
+ name : "test special chars" ,
234
+ arg : "home of and & or wiki page!" ,
235
+ hasWiki : true ,
236
+ wikiPath : "home-of-and-%26-or-wiki-page%21.md" ,
237
+ wantErr : false ,
238
+ }, {
239
+ name : "strange cases" ,
240
+ arg : "..." ,
241
+ hasWiki : true ,
242
+ wikiPath : "....md" ,
243
+ wantErr : false ,
244
+ }}
245
+ for _ , tt := range tests {
246
+ t .Run (tt .name , func (t * testing.T ) {
247
+ isWikiExist , newWikiPath , err := prepareWikiFileName (gitRepo , tt .arg )
248
+ if (err != nil ) != tt .wantErr {
249
+ assert .NoError (t , err )
250
+ return
251
+ }
252
+ if isWikiExist != tt .hasWiki {
253
+ if isWikiExist {
254
+ t .Errorf ("expect to have no wiki but we detect one" )
255
+ } else {
256
+ t .Errorf ("expect to have wiki but we could not detect one" )
257
+ }
258
+ }
259
+ assert .Equal (t , tt .wikiPath , newWikiPath )
260
+ })
261
+ }
262
+ }
You can’t perform that action at this time.
0 commit comments