@@ -6,7 +6,10 @@ package integrations
6
6
7
7
import (
8
8
"fmt"
9
+ "io/ioutil"
9
10
"net/http"
11
+ "net/url"
12
+ "os"
10
13
"testing"
11
14
12
15
"code.gitea.io/gitea/models"
@@ -291,6 +294,44 @@ func TestAPIRepoMigrate(t *testing.T) {
291
294
}
292
295
}
293
296
297
+ func TestAPIRepoMigrateConflict (t * testing.T ) {
298
+ onGiteaRun (t , testAPIRepoMigrateConflict )
299
+ }
300
+
301
+ func testAPIRepoMigrateConflict (t * testing.T , u * url.URL ) {
302
+ username := "user2"
303
+ baseAPITestContext := NewAPITestContext (t , username , "repo1" )
304
+
305
+ u .Path = baseAPITestContext .GitPath ()
306
+
307
+ t .Run ("Existing" , func (t * testing.T ) {
308
+ httpContext := baseAPITestContext
309
+
310
+ httpContext .Reponame = "repo-tmp-17"
311
+ dstPath , err := ioutil .TempDir ("" , httpContext .Reponame )
312
+ assert .NoError (t , err )
313
+ defer os .RemoveAll (dstPath )
314
+ t .Run ("CreateRepo" , doAPICreateRepository (httpContext , false ))
315
+
316
+ user , err := models .GetUserByName (httpContext .Username )
317
+ assert .NoError (t , err )
318
+ userID := user .ID
319
+
320
+ cloneURL := "https://github.com/go-gitea/git.git"
321
+
322
+ req := NewRequestWithJSON (t , "POST" , "/api/v1/repos/migrate?token=" + httpContext .Token ,
323
+ & api.MigrateRepoOption {
324
+ CloneAddr : cloneURL ,
325
+ UID : int (userID ),
326
+ RepoName : httpContext .Reponame ,
327
+ })
328
+ resp := httpContext .Session .MakeRequest (t , req , http .StatusConflict )
329
+ respJSON := map [string ]string {}
330
+ DecodeJSON (t , resp , & respJSON )
331
+ assert .Equal (t , respJSON ["message" ], "The repository with the same name already exists." )
332
+ })
333
+ }
334
+
294
335
func TestAPIOrgRepoCreate (t * testing.T ) {
295
336
testCases := []struct {
296
337
ctxUserID int64
@@ -313,3 +354,33 @@ func TestAPIOrgRepoCreate(t *testing.T) {
313
354
session .MakeRequest (t , req , testCase .expectedStatus )
314
355
}
315
356
}
357
+
358
+ func TestAPIRepoCreateConflict (t * testing.T ) {
359
+ onGiteaRun (t , testAPIRepoCreateConflict )
360
+ }
361
+
362
+ func testAPIRepoCreateConflict (t * testing.T , u * url.URL ) {
363
+ username := "user2"
364
+ baseAPITestContext := NewAPITestContext (t , username , "repo1" )
365
+
366
+ u .Path = baseAPITestContext .GitPath ()
367
+
368
+ t .Run ("Existing" , func (t * testing.T ) {
369
+ httpContext := baseAPITestContext
370
+
371
+ httpContext .Reponame = "repo-tmp-17"
372
+ dstPath , err := ioutil .TempDir ("" , httpContext .Reponame )
373
+ assert .NoError (t , err )
374
+ defer os .RemoveAll (dstPath )
375
+ t .Run ("CreateRepo" , doAPICreateRepository (httpContext , false ))
376
+
377
+ req := NewRequestWithJSON (t , "POST" , "/api/v1/user/repos?token=" + httpContext .Token ,
378
+ & api.CreateRepoOption {
379
+ Name : httpContext .Reponame ,
380
+ })
381
+ resp := httpContext .Session .MakeRequest (t , req , http .StatusConflict )
382
+ respJSON := map [string ]string {}
383
+ DecodeJSON (t , resp , & respJSON )
384
+ assert .Equal (t , respJSON ["message" ], "The repository with the same name already exists." )
385
+ })
386
+ }
0 commit comments