2017-02-28 15:28:50 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-02-28 15:28:50 +05:30
|
|
|
|
2022-06-06 13:31:49 +05:30
|
|
|
package repo_test
|
2017-02-28 15:28:50 +05:30
|
|
|
|
|
|
|
import (
|
2022-05-21 14:45:40 +05:30
|
|
|
"strings"
|
2017-02-28 15:28:50 +05:30
|
|
|
"testing"
|
|
|
|
|
2021-09-19 17:19:59 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-06 13:31:49 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2017-10-27 02:46:13 +05:30
|
|
|
"code.gitea.io/gitea/modules/util"
|
|
|
|
|
2017-02-28 15:28:50 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2019-08-25 22:36:36 +05:30
|
|
|
func TestSearchRepository(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2017-02-28 15:28:50 +05:30
|
|
|
|
|
|
|
// test search public repository on explore page
|
2022-11-19 13:42:33 +05:30
|
|
|
repos, count, err := repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{
|
2020-01-25 00:30:29 +05:30
|
|
|
Page: 1,
|
|
|
|
PageSize: 10,
|
|
|
|
},
|
2017-10-27 02:46:13 +05:30
|
|
|
Keyword: "repo_12",
|
|
|
|
Collaborate: util.OptionalBoolFalse,
|
2017-02-28 15:28:50 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
2017-08-28 07:03:38 +05:30
|
|
|
if assert.Len(t, repos, 1) {
|
|
|
|
assert.Equal(t, "test_repo_12", repos[0].Name)
|
|
|
|
}
|
2017-02-28 15:28:50 +05:30
|
|
|
assert.Equal(t, int64(1), count)
|
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{
|
2020-01-25 00:30:29 +05:30
|
|
|
Page: 1,
|
|
|
|
PageSize: 10,
|
|
|
|
},
|
2017-10-27 02:46:13 +05:30
|
|
|
Keyword: "test_repo",
|
|
|
|
Collaborate: util.OptionalBoolFalse,
|
2017-02-28 15:28:50 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(2), count)
|
2017-10-10 06:53:29 +05:30
|
|
|
assert.Len(t, repos, 2)
|
2017-02-28 15:28:50 +05:30
|
|
|
|
|
|
|
// test search private repository on explore page
|
2022-11-19 13:42:33 +05:30
|
|
|
repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{
|
2020-01-25 00:30:29 +05:30
|
|
|
Page: 1,
|
|
|
|
PageSize: 10,
|
|
|
|
},
|
2017-10-27 02:46:13 +05:30
|
|
|
Keyword: "repo_13",
|
|
|
|
Private: true,
|
|
|
|
Collaborate: util.OptionalBoolFalse,
|
2017-02-28 15:28:50 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
2017-08-28 07:03:38 +05:30
|
|
|
if assert.Len(t, repos, 1) {
|
|
|
|
assert.Equal(t, "test_repo_13", repos[0].Name)
|
|
|
|
}
|
2017-02-28 15:28:50 +05:30
|
|
|
assert.Equal(t, int64(1), count)
|
|
|
|
|
2022-11-19 13:42:33 +05:30
|
|
|
repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{
|
2020-01-25 00:30:29 +05:30
|
|
|
Page: 1,
|
|
|
|
PageSize: 10,
|
|
|
|
},
|
2017-10-27 02:46:13 +05:30
|
|
|
Keyword: "test_repo",
|
|
|
|
Private: true,
|
|
|
|
Collaborate: util.OptionalBoolFalse,
|
2017-02-28 15:28:50 +05:30
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(3), count)
|
2017-10-10 06:53:29 +05:30
|
|
|
assert.Len(t, repos, 3)
|
|
|
|
|
2017-10-27 02:46:13 +05:30
|
|
|
// Test non existing owner
|
2022-11-19 13:42:33 +05:30
|
|
|
repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{OwnerID: unittest.NonexistentID})
|
2017-10-27 02:46:13 +05:30
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, repos)
|
|
|
|
assert.Equal(t, int64(0), count)
|
|
|
|
|
2019-08-25 22:36:36 +05:30
|
|
|
// Test search within description
|
2022-11-19 13:42:33 +05:30
|
|
|
repos, count, err = repo_model.SearchRepository(db.DefaultContext, &repo_model.SearchRepoOptions{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{
|
2020-01-25 00:30:29 +05:30
|
|
|
Page: 1,
|
|
|
|
PageSize: 10,
|
|
|
|
},
|
2019-08-25 22:36:36 +05:30
|
|
|
Keyword: "description_14",
|
|
|
|
Collaborate: util.OptionalBoolFalse,
|
|
|
|
IncludeDescription: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
if assert.Len(t, repos, 1) {
|
|
|
|
assert.Equal(t, "test_repo_14", repos[0].Name)
|
|
|
|
}
|
|
|
|
assert.Equal(t, int64(1), count)
|
|
|
|
|
|
|
|
// Test NOT search within description
|
2022-11-19 13:42:33 +05:30
|
|
|
repos, count, err = repo_model.SearchRepository(db.DefaultContext, &repo_model.SearchRepoOptions{
|
2021-09-24 17:02:56 +05:30
|
|
|
ListOptions: db.ListOptions{
|
2020-01-25 00:30:29 +05:30
|
|
|
Page: 1,
|
|
|
|
PageSize: 10,
|
|
|
|
},
|
2019-08-25 22:36:36 +05:30
|
|
|
Keyword: "description_14",
|
|
|
|
Collaborate: util.OptionalBoolFalse,
|
|
|
|
IncludeDescription: false,
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, repos)
|
|
|
|
assert.Equal(t, int64(0), count)
|
|
|
|
|
2017-10-10 06:53:29 +05:30
|
|
|
testCases := []struct {
|
|
|
|
name string
|
2022-06-06 13:31:49 +05:30
|
|
|
opts *repo_model.SearchRepoOptions
|
2017-10-10 06:53:29 +05:30
|
|
|
count int
|
|
|
|
}{
|
2021-03-15 00:22:12 +05:30
|
|
|
{
|
|
|
|
name: "PublicRepositoriesByName",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{PageSize: 10}, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 7,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesByName",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 14,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFirstPage",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 1, PageSize: 5}, Private: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 14,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitSecondPage",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 2, PageSize: 5}, Private: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 14,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitThirdPage",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 3, PageSize: 5}, Private: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 14,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFourthPage",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 3, PageSize: 5}, Private: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 14,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicRepositoriesOfUser",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicRepositoriesOfUser2",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicRepositoriesOfUser3",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesOfUser",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 4,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesOfUser2",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesOfUser3",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Private: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 4,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicRepositoriesOfUserIncludingCollaborative",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 5,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicRepositoriesOfUser2IncludingCollaborative",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicRepositoriesOfUser3IncludingCollaborative",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 9,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesOfUser2IncludingCollaborative",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 4,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesOfUser3IncludingCollaborative",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Private: true},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 7,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicRepositoriesOfOrganization",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "PublicAndPrivateRepositoriesOfOrganization",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, Private: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllPublic/PublicRepositoriesByName",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{PageSize: 10}, AllPublic: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 7,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllPublic/PublicAndPrivateRepositoriesByName",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, AllPublic: true, Collaborate: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 14,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 28,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 33,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "test", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 15,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllPublic/PublicAndPrivateRepositoriesOfUser2IncludingCollaborativeByName",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "test", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true, AllPublic: true},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 13,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllPublic/PublicRepositoriesOfOrganization",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: util.OptionalBoolFalse, Template: util.OptionalBoolFalse},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 28,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllTemplates",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Template: util.OptionalBoolTrue},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 2,
|
|
|
|
},
|
2022-05-21 14:45:40 +05:30
|
|
|
{
|
|
|
|
name: "OwnerSlashRepoSearch",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "user/repo2", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, OwnerID: 0},
|
2022-05-21 14:45:40 +05:30
|
|
|
count: 3,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "OwnerSlashSearch",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{Keyword: "user20/", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, OwnerID: 0},
|
2022-05-21 14:45:40 +05:30
|
|
|
count: 4,
|
|
|
|
},
|
2017-10-10 06:53:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2022-11-19 13:42:33 +05:30
|
|
|
repos, count, err := repo_model.SearchRepositoryByName(db.DefaultContext, testCase.opts)
|
2017-10-10 06:53:29 +05:30
|
|
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(testCase.count), count)
|
|
|
|
|
2017-10-27 02:46:13 +05:30
|
|
|
page := testCase.opts.Page
|
|
|
|
if page <= 0 {
|
|
|
|
page = 1
|
|
|
|
}
|
2021-03-15 00:22:12 +05:30
|
|
|
expectedLen := testCase.opts.PageSize
|
2017-10-27 02:46:13 +05:30
|
|
|
if testCase.opts.PageSize*page > testCase.count+testCase.opts.PageSize {
|
|
|
|
expectedLen = 0
|
|
|
|
} else if testCase.opts.PageSize*page > testCase.count {
|
2017-10-10 06:53:29 +05:30
|
|
|
expectedLen = testCase.count % testCase.opts.PageSize
|
|
|
|
}
|
2017-10-27 02:46:13 +05:30
|
|
|
if assert.Len(t, repos, expectedLen) {
|
|
|
|
for _, repo := range repos {
|
|
|
|
assert.NotEmpty(t, repo.Name)
|
|
|
|
|
|
|
|
if len(testCase.opts.Keyword) > 0 {
|
2022-05-21 14:45:40 +05:30
|
|
|
// Keyword match condition is different for search terms of form "owner/repo"
|
|
|
|
if strings.Count(testCase.opts.Keyword, "/") == 1 {
|
|
|
|
// May still match as a whole...
|
|
|
|
wholeMatch := strings.Contains(repo.Name, testCase.opts.Keyword)
|
|
|
|
|
|
|
|
pieces := strings.Split(testCase.opts.Keyword, "/")
|
|
|
|
ownerName := pieces[0]
|
|
|
|
repoName := pieces[1]
|
|
|
|
// ... or match in parts
|
|
|
|
splitMatch := strings.Contains(repo.OwnerName, ownerName) && strings.Contains(repo.Name, repoName)
|
|
|
|
|
|
|
|
assert.True(t, wholeMatch || splitMatch, "Keyword '%s' does not match repo '%s/%s'", testCase.opts.Keyword, repo.Owner.Name, repo.Name)
|
|
|
|
} else {
|
|
|
|
assert.Contains(t, repo.Name, testCase.opts.Keyword)
|
|
|
|
}
|
2017-10-27 02:46:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if !testCase.opts.Private {
|
|
|
|
assert.False(t, repo.IsPrivate)
|
|
|
|
}
|
|
|
|
|
|
|
|
if testCase.opts.Fork == util.OptionalBoolTrue && testCase.opts.Mirror == util.OptionalBoolTrue {
|
|
|
|
assert.True(t, repo.IsFork || repo.IsMirror)
|
|
|
|
} else {
|
|
|
|
switch testCase.opts.Fork {
|
|
|
|
case util.OptionalBoolFalse:
|
|
|
|
assert.False(t, repo.IsFork)
|
|
|
|
case util.OptionalBoolTrue:
|
|
|
|
assert.True(t, repo.IsFork)
|
|
|
|
}
|
|
|
|
|
|
|
|
switch testCase.opts.Mirror {
|
|
|
|
case util.OptionalBoolFalse:
|
|
|
|
assert.False(t, repo.IsMirror)
|
|
|
|
case util.OptionalBoolTrue:
|
|
|
|
assert.True(t, repo.IsMirror)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if testCase.opts.OwnerID > 0 && !testCase.opts.AllPublic {
|
|
|
|
switch testCase.opts.Collaborate {
|
|
|
|
case util.OptionalBoolFalse:
|
|
|
|
assert.Equal(t, testCase.opts.OwnerID, repo.Owner.ID)
|
|
|
|
case util.OptionalBoolTrue:
|
|
|
|
assert.NotEqual(t, testCase.opts.OwnerID, repo.Owner.ID)
|
|
|
|
}
|
|
|
|
}
|
2017-10-10 06:53:29 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-02-28 15:28:50 +05:30
|
|
|
}
|
2018-09-13 08:03:48 +05:30
|
|
|
|
|
|
|
func TestSearchRepositoryByTopicName(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
2018-09-13 08:03:48 +05:30
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
2022-06-06 13:31:49 +05:30
|
|
|
opts *repo_model.SearchRepoOptions
|
2018-09-13 08:03:48 +05:30
|
|
|
count int
|
|
|
|
}{
|
2021-03-15 00:22:12 +05:30
|
|
|
{
|
|
|
|
name: "AllPublic/SearchPublicRepositoriesFromTopicAndName",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql"},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 2,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllPublic/OnlySearchPublicRepositoriesFromTopic",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql", TopicOnly: true},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "AllPublic/OnlySearchMultipleKeywordPublicRepositoriesFromTopic",
|
2022-06-06 13:31:49 +05:30
|
|
|
opts: &repo_model.SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql,golang", TopicOnly: true},
|
2021-03-15 00:22:12 +05:30
|
|
|
count: 2,
|
|
|
|
},
|
2018-09-13 08:03:48 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
t.Run(testCase.name, func(t *testing.T) {
|
2022-11-19 13:42:33 +05:30
|
|
|
_, count, err := repo_model.SearchRepositoryByName(db.DefaultContext, testCase.opts)
|
2018-09-13 08:03:48 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(testCase.count), count)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|