diff options
author | Morlinest <morlinest@gmail.com> | 2017-10-17 17:20:22 +0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-10-17 23:20:22 +0800 |
commit | ccd3577970b64078eb156a736b1583833f80b4a3 (patch) | |
tree | 4abdd588adfc3f24992953ba2ad6fe0dcf614a6e /models/repo_list_test.go | |
parent | af4a094e5d1be13c0fe863c1cd6e56c62b1a9b79 (diff) | |
download | gitea-ccd3577970b64078eb156a736b1583833f80b4a3.tar.gz gitea-ccd3577970b64078eb156a736b1583833f80b4a3.zip |
Fix repository search function (#2689)
* Fix and remove FIXME
* Respect membership visibility
* Fix/rewrite searchRepositoryByName function
* Add unit tests
* Add integration tests
* Remove Searcher completely
* Remove trailing space
Diffstat (limited to 'models/repo_list_test.go')
-rw-r--r-- | models/repo_list_test.go | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/models/repo_list_test.go b/models/repo_list_test.go index 160ba57d32..4d125633a5 100644 --- a/models/repo_list_test.go +++ b/models/repo_list_test.go @@ -42,7 +42,6 @@ func TestSearchRepositoryByName(t *testing.T) { Page: 1, PageSize: 10, Private: true, - Searcher: &User{ID: 14}, }) assert.NoError(t, err) @@ -56,7 +55,6 @@ func TestSearchRepositoryByName(t *testing.T) { Page: 1, PageSize: 10, Private: true, - Searcher: &User{ID: 14}, }) assert.NoError(t, err) @@ -82,16 +80,28 @@ func TestSearchRepositoryByName(t *testing.T) { count: 8}, {name: "PublicRepositoriesOfUser", opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15}, - count: 3}, // FIXME: Should return 2 (only directly owned repositories), now includes 1 public repository from owned organization + count: 2}, + {name: "PublicRepositoriesOfUser2", + opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 18}, + count: 0}, {name: "PublicAndPrivateRepositoriesOfUser", opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true}, - count: 6}, // FIXME: Should return 4 (only directly owned repositories), now includes 2 repositories from owned organization + count: 4}, + {name: "PublicAndPrivateRepositoriesOfUser2", + opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 18, Private: true}, + count: 0}, {name: "PublicRepositoriesOfUserIncludingCollaborative", opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Collaborate: true}, count: 4}, + {name: "PublicRepositoriesOfUser2IncludingCollaborative", + opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 18, Collaborate: true}, + count: 1}, {name: "PublicAndPrivateRepositoriesOfUserIncludingCollaborative", opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, Collaborate: true}, count: 8}, + {name: "PublicAndPrivateRepositoriesOfUser2IncludingCollaborative", + opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 18, Private: true, Collaborate: true}, + count: 4}, {name: "PublicRepositoriesOfOrganization", opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 17}, count: 1}, @@ -113,6 +123,9 @@ func TestSearchRepositoryByName(t *testing.T) { {name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName", opts: &SearchRepoOptions{Keyword: "test", Page: 1, PageSize: 10, OwnerID: 15, Private: true, Collaborate: true, AllPublic: true}, count: 10}, + {name: "AllPublic/PublicAndPrivateRepositoriesOfUser2IncludingCollaborativeByName", + opts: &SearchRepoOptions{Keyword: "test", Page: 1, PageSize: 10, OwnerID: 18, Private: true, Collaborate: true, AllPublic: true}, + count: 8}, {name: "AllPublic/PublicRepositoriesOfOrganization", opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 17, AllPublic: true}, count: 12}, @@ -120,9 +133,6 @@ func TestSearchRepositoryByName(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { - if testCase.opts.OwnerID > 0 { - testCase.opts.Searcher = &User{ID: testCase.opts.OwnerID} - } repos, count, err := SearchRepositoryByName(testCase.opts) assert.NoError(t, err) @@ -143,10 +153,9 @@ func TestSearchRepositoryByName(t *testing.T) { assert.Contains(t, repo.Name, testCase.opts.Keyword) } - // FIXME: Can't check, need to fix current behaviour (see previous FIXME comments in test cases) - /*if testCase.opts.OwnerID > 0 && !testCase.opts.Collaborate && !AllPublic { + if testCase.opts.OwnerID > 0 && !testCase.opts.Collaborate && !testCase.opts.AllPublic { assert.Equal(t, testCase.opts.OwnerID, repo.Owner.ID) - }*/ + } if !testCase.opts.Private { assert.False(t, repo.IsPrivate) |