-
-
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
Changes from all commits
f6fca2e
0c4383b
2a848d1
c34d0bf
dbba93a
053da84
b14cacc
5f2b035
9f09b27
86bcf68
1670f15
4e32604
d4bd8d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,8 @@ func TestSearchRepositoryByName(t *testing.T) { | |
Keyword: "repo_12", | ||
Page: 1, | ||
PageSize: 10, | ||
Searcher: nil, | ||
}) | ||
|
||
assert.NotNil(t, repos) | ||
assert.NoError(t, err) | ||
if assert.Len(t, repos, 1) { | ||
assert.Equal(t, "test_repo_12", repos[0].Name) | ||
|
@@ -32,12 +30,11 @@ func TestSearchRepositoryByName(t *testing.T) { | |
Keyword: "test_repo", | ||
Page: 1, | ||
PageSize: 10, | ||
Searcher: nil, | ||
}) | ||
|
||
assert.NotNil(t, repos) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(2), count) | ||
assert.Len(t, repos, 2) | ||
|
||
// test search private repository on explore page | ||
repos, count, err = SearchRepositoryByName(&SearchRepoOptions{ | ||
|
@@ -48,7 +45,6 @@ func TestSearchRepositoryByName(t *testing.T) { | |
Searcher: &User{ID: 14}, | ||
}) | ||
|
||
assert.NotNil(t, repos) | ||
assert.NoError(t, err) | ||
if assert.Len(t, repos, 1) { | ||
assert.Equal(t, "test_repo_13", repos[0].Name) | ||
|
@@ -63,7 +59,81 @@ func TestSearchRepositoryByName(t *testing.T) { | |
Searcher: &User{ID: 14}, | ||
}) | ||
|
||
assert.NotNil(t, repos) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(3), count) | ||
assert.Len(t, repos, 3) | ||
|
||
testCases := []struct { | ||
name string | ||
opts *SearchRepoOptions | ||
count int | ||
}{ | ||
{name: "PublicRepositoriesByName", | ||
opts: &SearchRepoOptions{Keyword: "big_test_", PageSize: 10}, | ||
count: 4}, | ||
{name: "PublicAndPrivateRepositoriesByName", | ||
opts: &SearchRepoOptions{Keyword: "big_test_", Page: 1, PageSize: 10, Private: true}, | ||
count: 8}, | ||
{name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFirstPage", | ||
opts: &SearchRepoOptions{Keyword: "big_test_", Page: 1, PageSize: 5, Private: true}, | ||
count: 8}, | ||
{name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitSecondPage", | ||
opts: &SearchRepoOptions{Keyword: "big_test_", Page: 2, PageSize: 5, Private: true}, | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Organization and other repositories related to user should be included only if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. Should be |
||
{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 commentThe reason will be displayed to describe this comment to others. Learn more. You are right. Should be |
||
{name: "PublicRepositoriesOfUserIncludingCollaborative", | ||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Collaborate: true}, | ||
count: 4}, | ||
{name: "PublicAndPrivateRepositoriesOfUserIncludingCollaborative", | ||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 15, Private: true, Collaborate: true}, | ||
count: 8}, | ||
{name: "PublicRepositoriesOfOrganization", | ||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 17}, | ||
count: 1}, | ||
{name: "PublicAndPrivateRepositoriesOfOrganization", | ||
opts: &SearchRepoOptions{Page: 1, PageSize: 10, OwnerID: 17, Private: true}, | ||
count: 2}, | ||
} | ||
|
||
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) | ||
assert.Equal(t, int64(testCase.count), count) | ||
|
||
var expectedLen int | ||
if testCase.opts.PageSize*testCase.opts.Page > testCase.count { | ||
expectedLen = testCase.count % testCase.opts.PageSize | ||
} else { | ||
expectedLen = testCase.opts.PageSize | ||
} | ||
assert.Len(t, repos, expectedLen) | ||
|
||
for _, repo := range repos { | ||
assert.NotEmpty(t, repo.Name) | ||
|
||
if len(testCase.opts.Keyword) > 0 { | ||
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 { | ||
assert.Equal(t, testCase.opts.OwnerID, repo.Owner.ID) | ||
}*/ | ||
|
||
if !testCase.opts.Private { | ||
assert.False(t, repo.IsPrivate) | ||
} | ||
} | ||
}) | ||
} | ||
} |
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