From 43c94d0a6cd8daf01125df3bf895f1beb1bcd664 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 15 Feb 2017 23:24:23 +0800 Subject: [PATCH] test: Add testing for GetUserFork function (#944) --- models/fixtures/repository.yml | 26 ++++++++++++++++++++++++++ models/fixtures/user.yml | 30 ++++++++++++++++++++++++++++++ models/repo_test.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) 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)) +}