mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user