test: Add testing for GetUserFork function (#944)

This commit is contained in:
Bo-Yi Wu 2017-02-15 23:24:23 +08:00 committed by Lunny Xiao
parent a31f64d639
commit 43c94d0a6c
3 changed files with 89 additions and 0 deletions

View File

@ -105,3 +105,29 @@
num_pulls: 0 num_pulls: 0
num_closed_pulls: 0 num_closed_pulls: 0
is_mirror: false 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

View File

@ -164,3 +164,33 @@
avatar_email: user11@example.com avatar_email: user11@example.com
num_repos: 1 num_repos: 1
is_active: true 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

View File

@ -92,3 +92,36 @@ func TestUpdateRepositoryVisibilityChanged(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, true, act.IsPrivate) 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))
}