aboutsummaryrefslogtreecommitdiffstats
path: root/models/repo_list_test.go
diff options
context:
space:
mode:
authorBo-Yi Wu <appleboy.tw@gmail.com>2021-03-15 02:52:12 +0800
committerGitHub <noreply@github.com>2021-03-14 19:52:12 +0100
commit167b0f46ef946fad3ca13976c3b87598f505e2ea (patch)
tree8b6a4a47a2a0149899b3eb49b296677c2dba4d36 /models/repo_list_test.go
parent164e35ead3c1b9b82d4a23644f6fe96652a747eb (diff)
downloadgitea-167b0f46ef946fad3ca13976c3b87598f505e2ea.tar.gz
gitea-167b0f46ef946fad3ca13976c3b87598f505e2ea.zip
chore(models): rewrite code format. (#14754)
* chore: rewrite format. * chore: update format Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * chore: update format Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * chore: Adjacent parameters with the same type should be grouped together * chore: update format.
Diffstat (limited to 'models/repo_list_test.go')
-rw-r--r--models/repo_list_test.go188
1 files changed, 125 insertions, 63 deletions
diff --git a/models/repo_list_test.go b/models/repo_list_test.go
index 37af9d598d..d1fefc3e32 100644
--- a/models/repo_list_test.go
+++ b/models/repo_list_test.go
@@ -119,90 +119,146 @@ func TestSearchRepository(t *testing.T) {
opts *SearchRepoOptions
count int
}{
- {name: "PublicRepositoriesByName",
+ {
+ name: "PublicRepositoriesByName",
opts: &SearchRepoOptions{Keyword: "big_test_", ListOptions: ListOptions{PageSize: 10}, Collaborate: util.OptionalBoolFalse},
- count: 7},
- {name: "PublicAndPrivateRepositoriesByName",
+ count: 7,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesByName",
opts: &SearchRepoOptions{Keyword: "big_test_", ListOptions: ListOptions{Page: 1, PageSize: 10}, Private: true, Collaborate: util.OptionalBoolFalse},
- count: 14},
- {name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFirstPage",
+ count: 14,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFirstPage",
opts: &SearchRepoOptions{Keyword: "big_test_", ListOptions: ListOptions{Page: 1, PageSize: 5}, Private: true, Collaborate: util.OptionalBoolFalse},
- count: 14},
- {name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitSecondPage",
+ count: 14,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitSecondPage",
opts: &SearchRepoOptions{Keyword: "big_test_", ListOptions: ListOptions{Page: 2, PageSize: 5}, Private: true, Collaborate: util.OptionalBoolFalse},
- count: 14},
- {name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitThirdPage",
+ count: 14,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitThirdPage",
opts: &SearchRepoOptions{Keyword: "big_test_", ListOptions: ListOptions{Page: 3, PageSize: 5}, Private: true, Collaborate: util.OptionalBoolFalse},
- count: 14},
- {name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFourthPage",
+ count: 14,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFourthPage",
opts: &SearchRepoOptions{Keyword: "big_test_", ListOptions: ListOptions{Page: 3, PageSize: 5}, Private: true, Collaborate: util.OptionalBoolFalse},
- count: 14},
- {name: "PublicRepositoriesOfUser",
+ count: 14,
+ },
+ {
+ name: "PublicRepositoriesOfUser",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Collaborate: util.OptionalBoolFalse},
- count: 2},
- {name: "PublicRepositoriesOfUser2",
+ count: 2,
+ },
+ {
+ name: "PublicRepositoriesOfUser2",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Collaborate: util.OptionalBoolFalse},
- count: 0},
- {name: "PublicRepositoriesOfUser3",
+ count: 0,
+ },
+ {
+ name: "PublicRepositoriesOfUser3",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Collaborate: util.OptionalBoolFalse},
- count: 2},
- {name: "PublicAndPrivateRepositoriesOfUser",
+ count: 2,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesOfUser",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, Collaborate: util.OptionalBoolFalse},
- count: 4},
- {name: "PublicAndPrivateRepositoriesOfUser2",
+ count: 4,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesOfUser2",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true, Collaborate: util.OptionalBoolFalse},
- count: 0},
- {name: "PublicAndPrivateRepositoriesOfUser3",
+ count: 0,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesOfUser3",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Private: true, Collaborate: util.OptionalBoolFalse},
- count: 4},
- {name: "PublicRepositoriesOfUserIncludingCollaborative",
+ count: 4,
+ },
+ {
+ name: "PublicRepositoriesOfUserIncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 15},
- count: 5},
- {name: "PublicRepositoriesOfUser2IncludingCollaborative",
+ count: 5,
+ },
+ {
+ name: "PublicRepositoriesOfUser2IncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 18},
- count: 1},
- {name: "PublicRepositoriesOfUser3IncludingCollaborative",
+ count: 1,
+ },
+ {
+ name: "PublicRepositoriesOfUser3IncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 20},
- count: 3},
- {name: "PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
+ count: 3,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true},
- count: 9},
- {name: "PublicAndPrivateRepositoriesOfUser2IncludingCollaborative",
+ count: 9,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesOfUser2IncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true},
- count: 4},
- {name: "PublicAndPrivateRepositoriesOfUser3IncludingCollaborative",
+ count: 4,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesOfUser3IncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Private: true},
- count: 7},
- {name: "PublicRepositoriesOfOrganization",
+ count: 7,
+ },
+ {
+ name: "PublicRepositoriesOfOrganization",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, Collaborate: util.OptionalBoolFalse},
- count: 1},
- {name: "PublicAndPrivateRepositoriesOfOrganization",
+ count: 1,
+ },
+ {
+ name: "PublicAndPrivateRepositoriesOfOrganization",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, Private: true, Collaborate: util.OptionalBoolFalse},
- count: 2},
- {name: "AllPublic/PublicRepositoriesByName",
+ count: 2,
+ },
+ {
+ name: "AllPublic/PublicRepositoriesByName",
opts: &SearchRepoOptions{Keyword: "big_test_", ListOptions: ListOptions{PageSize: 10}, AllPublic: true, Collaborate: util.OptionalBoolFalse},
- count: 7},
- {name: "AllPublic/PublicAndPrivateRepositoriesByName",
+ count: 7,
+ },
+ {
+ name: "AllPublic/PublicAndPrivateRepositoriesByName",
opts: &SearchRepoOptions{Keyword: "big_test_", ListOptions: ListOptions{Page: 1, PageSize: 10}, Private: true, AllPublic: true, Collaborate: util.OptionalBoolFalse},
- count: 14},
- {name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
+ count: 14,
+ },
+ {
+ name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
- count: 28},
- {name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
+ count: 28,
+ },
+ {
+ name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
- count: 33},
- {name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
+ count: 33,
+ },
+ {
+ name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
opts: &SearchRepoOptions{Keyword: "test", ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true},
- count: 15},
- {name: "AllPublic/PublicAndPrivateRepositoriesOfUser2IncludingCollaborativeByName",
+ count: 15,
+ },
+ {
+ name: "AllPublic/PublicAndPrivateRepositoriesOfUser2IncludingCollaborativeByName",
opts: &SearchRepoOptions{Keyword: "test", ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true, AllPublic: true},
- count: 13},
- {name: "AllPublic/PublicRepositoriesOfOrganization",
+ count: 13,
+ },
+ {
+ name: "AllPublic/PublicRepositoriesOfOrganization",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
- count: 28},
- {name: "AllTemplates",
+ count: 28,
+ },
+ {
+ name: "AllTemplates",
opts: &SearchRepoOptions{ListOptions: ListOptions{Page: 1, PageSize: 10}, Template: util.OptionalBoolTrue},
- count: 2},
+ count: 2,
+ },
}
for _, testCase := range testCases {
@@ -216,7 +272,7 @@ func TestSearchRepository(t *testing.T) {
if page <= 0 {
page = 1
}
- var expectedLen = testCase.opts.PageSize
+ expectedLen := testCase.opts.PageSize
if testCase.opts.PageSize*page > testCase.count+testCase.opts.PageSize {
expectedLen = 0
} else if testCase.opts.PageSize*page > testCase.count {
@@ -274,15 +330,21 @@ func TestSearchRepositoryByTopicName(t *testing.T) {
opts *SearchRepoOptions
count int
}{
- {name: "AllPublic/SearchPublicRepositoriesFromTopicAndName",
+ {
+ name: "AllPublic/SearchPublicRepositoriesFromTopicAndName",
opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql"},
- count: 2},
- {name: "AllPublic/OnlySearchPublicRepositoriesFromTopic",
+ count: 2,
+ },
+ {
+ name: "AllPublic/OnlySearchPublicRepositoriesFromTopic",
opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql", TopicOnly: true},
- count: 1},
- {name: "AllPublic/OnlySearchMultipleKeywordPublicRepositoriesFromTopic",
+ count: 1,
+ },
+ {
+ name: "AllPublic/OnlySearchMultipleKeywordPublicRepositoriesFromTopic",
opts: &SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql,golang", TopicOnly: true},
- count: 2},
+ count: 2,
+ },
}
for _, testCase := range testCases {