-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add repository search unit and integration tests #2575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add repository search unit and integration tests #2575
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2575 +/- ##
==========================================
+ Coverage 27.13% 27.28% +0.15%
==========================================
Files 86 86
Lines 17062 17062
==========================================
+ Hits 4629 4655 +26
+ Misses 11755 11728 -27
- Partials 678 679 +1
Continue to review full report at Codecov.
|
integrations/api_repo_test.go
Outdated
user2: {count: 4, repoName: "big_test_", privacy: privacyTypePublic}}, | ||
}, | ||
{name: "RepositoriesAccessibleAndRelatedToUser", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user.ID), expectedResults: expectedResults{ | ||
// FIXME: Should return 4 (all public repositories related to "another" user = owned + collaborative), now returns only public repositories directly owned by user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but here is no user login, what's collaborative?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repositories related to user.ID
. In my opinion logged user is here only to check rights. That means logged user and anonymous user has same rights if searching for repositories related to another user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But collaborative also includes repositories the user has contributed to. Don't think thats right.
IMO the question is: transitive owning!? (user owns org, org owns repo => user owns repo?) @bkcsoft and me have discussed that already in discord.
His and my opinion was to include org-repos as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daviian It includes repositories, for which user has some rights through teams. In dashboard, collaborative
is defined as ownerID != userID
and Source
as ownerID == userID
. You don't know that user is owner of organization from api/repo/search result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you own organization, you are automaticaly in Owners
team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a vote on the expected behaviour of this API call.
@go-gitea/owners
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunny @Morlinest I compared the result to githubs implementation. Github doesn't include any repositories from organizations (even owned ones) when searching for repositories of a user. So I think 2
is correct.
Please add check for repoOwnerID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need collaborative for our dashboard we should include it in "public" search as well, but limited to public orgs and membership and public repositories.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment from above. Transitive owning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Organization and other repositories related to user should be included only if collaborate
option is supplied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Should be 2
here.
8e0c288
to
40efd7c
Compare
integrations/api_repo_test.go
Outdated
user2: {count: 4, repoName: "big_test_", privacy: privacyTypePublic}}, | ||
}, | ||
{name: "RepositoriesAccessibleAndRelatedToUser", requestURL: fmt.Sprintf("/api/v1/repos/search?uid=%d", user.ID), expectedResults: expectedResults{ | ||
// FIXME: Should return 4 (all public repositories related to "another" user = owned + collaborative), now returns only public repositories directly owned by user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunny @Morlinest I compared the result to githubs implementation. Github doesn't include any repositories from organizations (even owned ones) when searching for repositories of a user. So I think 2
is correct.
Please add check for repoOwnerID
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Should be 2
here.
count: 3}, // FIXME: Should return 2 (only directly owned repositories), now includes 1 public repository from owned organization | ||
{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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. Should be 4
here.
integrations/api_repo_test.go
Outdated
nil: {count: 1, privacy: privacyTypePublic}, | ||
user: {count: 1, privacy: privacyTypePublic}, | ||
user2: {count: 2}}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add check for repoOwnerID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not possible, since includes collaborative too
models/repo_list_test.go
Outdated
|
||
// test search private repository on explore page | ||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{ | ||
Keyword: "repo_13", | ||
Page: 1, | ||
PageSize: 10, | ||
Private: true, | ||
Searcher: &User{ID: 14}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO you should leave it as it is.
Although the implementation doesn't need it because no OwnerID i set, but it could be a test that it has no impact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
models/repo_list_test.go
Outdated
@@ -60,10 +55,66 @@ func TestSearchRepositoryByName(t *testing.T) { | |||
Page: 1, | |||
PageSize: 10, | |||
Private: true, | |||
Searcher: &User{ID: 14}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
count int | ||
}{ | ||
{name: "PublicRepositoriesByName", | ||
opts: &SearchRepoOptions{Keyword: "big_test_", PageSize: 10}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add similar checks as in api_repo_tests for all test cases. E.g. repo name, private/public repositories
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@Morlinest Please rebase :) |
40efd7c
to
198c2f9
Compare
LGTM |
0bae86d
to
d4bd8d7
Compare
LGTM |
Extracted from #2371. Adds only tests, no feature/fix. Please read
FIXME
comments (4x).