diff options
author | Bo-Yi Wu <appleboy.tw@gmail.com> | 2017-02-15 23:24:23 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-15 23:24:23 +0800 |
commit | 43c94d0a6cd8daf01125df3bf895f1beb1bcd664 (patch) | |
tree | 06973f77f683d30f3efab45a5f2d9e5a9c9c7726 /models | |
parent | a31f64d639f32ee4ef428e76277eb0b0bf5616c4 (diff) | |
download | gitea-43c94d0a6cd8daf01125df3bf895f1beb1bcd664.tar.gz gitea-43c94d0a6cd8daf01125df3bf895f1beb1bcd664.zip |
test: Add testing for GetUserFork function (#944)
Diffstat (limited to 'models')
-rw-r--r-- | models/fixtures/repository.yml | 26 | ||||
-rw-r--r-- | models/fixtures/user.yml | 30 | ||||
-rw-r--r-- | models/repo_test.go | 33 |
3 files changed, 89 insertions, 0 deletions
diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index d50b88c301..873eb612c7 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -105,3 +105,29 @@ num_pulls: 0 num_closed_pulls: 0 is_mirror: false + +- + id: 10 + owner_id: 12 + lower_name: repo10 + name: repo10 + is_private: false + num_issues: 0 + num_closed_issues: 0 + num_pulls: 0 + num_closed_pulls: 0 + is_mirror: false + num_forks: 1 + +- + id: 11 + fork_id: 10 + owner_id: 13 + lower_name: repo11 + name: repo11 + is_private: false + num_issues: 0 + num_closed_issues: 0 + num_pulls: 0 + num_closed_pulls: 0 + is_mirror: false diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 337fb54590..8874498c91 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -164,3 +164,33 @@ avatar_email: user11@example.com num_repos: 1 is_active: true + +- + id: 12 + lower_name: user12 + name: user12 + full_name: User 12 + email: user12@example.com + passwd: password + type: 0 # individual + salt: salt + is_admin: false + avatar: avatar12 + avatar_email: user12@example.com + num_repos: 1 + is_active: true + +- + id: 13 + lower_name: user13 + name: user13 + full_name: User 13 + email: user13@example.com + passwd: password + type: 0 # individual + salt: salt + is_admin: false + avatar: avatar13 + avatar_email: user13@example.com + num_repos: 1 + is_active: true diff --git a/models/repo_test.go b/models/repo_test.go index 18da682059..7c0e94a5ae 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -92,3 +92,36 @@ func TestUpdateRepositoryVisibilityChanged(t *testing.T) { assert.NoError(t, err) assert.Equal(t, true, act.IsPrivate) } + +func TestGetUserFork(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + // User13 has repo 11 forked from repo10 + repo, err := GetRepositoryByID(10) + assert.NoError(t, err) + assert.NotNil(t, repo) + repo, err = repo.GetUserFork(13) + assert.NoError(t, err) + assert.NotNil(t, repo) + + repo, err = GetRepositoryByID(9) + assert.NoError(t, err) + assert.NotNil(t, repo) + repo, err = repo.GetUserFork(13) + assert.NoError(t, err) + assert.Nil(t, repo) +} + +func TestForkRepository(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + // User13 has repo 11 forked from repo10 + repo, err := GetRepositoryByID(10) + assert.NoError(t, err) + assert.NotNil(t, repo) + + repo, err = ForkRepository(&User{ID: 13}, repo, "test", "test") + assert.Nil(t, repo) + assert.Error(t, err) + assert.True(t, IsErrRepoAlreadyExist(err)) +} |