summaryrefslogtreecommitdiffstats
path: root/models/repo_list_test.go
diff options
context:
space:
mode:
authorDavid Svantesson <davidsvantesson@gmail.com>2019-08-25 19:06:36 +0200
committerLauris BH <lauris@nix.lv>2019-08-25 20:06:36 +0300
commitc9546d4cdd5f7de8f56b7d4a9806d1aca784cf3f (patch)
treeeebd4affa86ae9d75b41590453a07af42db31fb0 /models/repo_list_test.go
parent8c24bb9e4344791ca2e8c66efcf3d45881365a5d (diff)
downloadgitea-c9546d4cdd5f7de8f56b7d4a9806d1aca784cf3f.tar.gz
gitea-c9546d4cdd5f7de8f56b7d4a9806d1aca784cf3f.zip
Include description in repository search. (#7942)
* Add description in repository search. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Refactor SearchRepositoryByName with a general function SearchRepository Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Allow to specify if description shall be included in API repo search. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Add new app.ini setting for whether to search within repo description. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Search keyword in description (if setting enabled) on: - Explore page - Organization profile page - User profile page - Admin repo page Do not search keyword in description on: - Any non-keyword search (not relevant) - Incremental search (uses API) Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Put parameters related to keyword directly after it Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Add test cases for including (and not including) repository description in search. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Rename test function from TestSearchRepositoryByName to TestSearchRepository. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Make setting SEARCH_REPO_DESCRIPTION default to true Signed-off-by: David Svantesson <davidsvantesson@gmail.com>
Diffstat (limited to 'models/repo_list_test.go')
-rw-r--r--models/repo_list_test.go30
1 files changed, 29 insertions, 1 deletions
diff --git a/models/repo_list_test.go b/models/repo_list_test.go
index 645de2a59a..76ae9ab3d7 100644
--- a/models/repo_list_test.go
+++ b/models/repo_list_test.go
@@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestSearchRepositoryByName(t *testing.T) {
+func TestSearchRepository(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
// test search public repository on explore page
@@ -74,6 +74,34 @@ func TestSearchRepositoryByName(t *testing.T) {
assert.Empty(t, repos)
assert.Equal(t, int64(0), count)
+ // Test search within description
+ repos, count, err = SearchRepository(&SearchRepoOptions{
+ Keyword: "description_14",
+ Page: 1,
+ PageSize: 10,
+ 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
+ repos, count, err = SearchRepository(&SearchRepoOptions{
+ Keyword: "description_14",
+ Page: 1,
+ PageSize: 10,
+ Collaborate: util.OptionalBoolFalse,
+ IncludeDescription: false,
+ })
+
+ assert.NoError(t, err)
+ assert.Empty(t, repos)
+ assert.Equal(t, int64(0), count)
+
testCases := []struct {
name string
opts *SearchRepoOptions