diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-09-16 13:16:21 -0700 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-09-16 23:16:21 +0300 |
commit | b0f7457d9ef6e16d4a3197f7544035d5d387e201 (patch) | |
tree | dbe6a9b3b74f9a4a6eaa0c0cfe59fa08509edccc /integrations | |
parent | 52e11b24bf5e395d83ea58c1b0fd6922efe16add (diff) | |
download | gitea-b0f7457d9ef6e16d4a3197f7544035d5d387e201.tar.gz gitea-b0f7457d9ef6e16d4a3197f7544035d5d387e201.zip |
Improve issue search (#2387)
* Improve issue indexer
* Fix new issue sqlite bug
* Different test indexer paths for each db
* Add integration indexer paths to make clean
Diffstat (limited to 'integrations')
-rw-r--r-- | integrations/integration_test.go | 9 | ||||
-rw-r--r-- | integrations/issue_test.go | 43 | ||||
-rw-r--r-- | integrations/mysql.ini.tmpl | 3 | ||||
-rw-r--r-- | integrations/pgsql.ini.tmpl | 3 | ||||
-rw-r--r-- | integrations/sqlite.ini | 3 |
5 files changed, 55 insertions, 6 deletions
diff --git a/integrations/integration_test.go b/integrations/integration_test.go index 0b5d8a764d..e18be523cb 100644 --- a/integrations/integration_test.go +++ b/integrations/integration_test.go @@ -57,7 +57,14 @@ func TestMain(m *testing.M) { fmt.Printf("Error initializing test database: %v\n", err) os.Exit(1) } - os.Exit(m.Run()) + exitCode := m.Run() + + if err = os.RemoveAll(setting.Indexer.IssuePath); err != nil { + fmt.Printf("os.RemoveAll: %v\n", err) + os.Exit(1) + } + + os.Exit(exitCode) } func initIntegrationTest() { diff --git a/integrations/issue_test.go b/integrations/issue_test.go index e728e4a154..e962ef2e93 100644 --- a/integrations/issue_test.go +++ b/integrations/issue_test.go @@ -18,8 +18,10 @@ import ( "github.com/stretchr/testify/assert" ) -func getIssuesSelection(htmlDoc *HTMLDoc) *goquery.Selection { - return htmlDoc.doc.Find(".issue.list").Find("li").Find(".title") +func getIssuesSelection(t testing.TB, htmlDoc *HTMLDoc) *goquery.Selection { + issueList := htmlDoc.doc.Find(".issue.list") + assert.EqualValues(t, 1, issueList.Length()) + return issueList.Find("li").Find(".title") } func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *models.Issue { @@ -31,6 +33,18 @@ func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *mo return models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repoID, Index: int64(index)}).(*models.Issue) } +func assertMatch(t testing.TB, issue *models.Issue, keyword string) { + matches := strings.Contains(strings.ToLower(issue.Title), keyword) || + strings.Contains(strings.ToLower(issue.Content), keyword) + for _, comment := range issue.Comments { + matches = matches || strings.Contains( + strings.ToLower(comment.Content), + keyword, + ) + } + assert.True(t, matches) +} + func TestNoLoginViewIssues(t *testing.T) { prepareTestEnv(t) @@ -38,19 +52,18 @@ func TestNoLoginViewIssues(t *testing.T) { MakeRequest(t, req, http.StatusOK) } -func TestNoLoginViewIssuesSortByType(t *testing.T) { +func TestViewIssuesSortByType(t *testing.T) { prepareTestEnv(t) user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) - repo.Owner = models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User) session := loginUser(t, user.Name) req := NewRequest(t, "GET", repo.RelLink()+"/issues?type=created_by") resp := session.MakeRequest(t, req, http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - issuesSelection := getIssuesSelection(htmlDoc) + issuesSelection := getIssuesSelection(t, htmlDoc) expectedNumIssues := models.GetCount(t, &models.Issue{RepoID: repo.ID, PosterID: user.ID}, models.Cond("is_closed=?", false), @@ -67,6 +80,26 @@ func TestNoLoginViewIssuesSortByType(t *testing.T) { }) } +func TestViewIssuesKeyword(t *testing.T) { + prepareTestEnv(t) + + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository) + + const keyword = "first" + req := NewRequestf(t, "GET", "%s/issues?q=%s", repo.RelLink(), keyword) + resp := MakeRequest(t, req, http.StatusOK) + + htmlDoc := NewHTMLParser(t, resp.Body) + issuesSelection := getIssuesSelection(t, htmlDoc) + assert.EqualValues(t, 1, issuesSelection.Length()) + issuesSelection.Each(func(_ int, selection *goquery.Selection) { + issue := getIssue(t, repo.ID, selection) + assert.False(t, issue.IsClosed) + assert.False(t, issue.IsPull) + assertMatch(t, issue, keyword) + }) +} + func TestNoLoginViewIssue(t *testing.T) { prepareTestEnv(t) diff --git a/integrations/mysql.ini.tmpl b/integrations/mysql.ini.tmpl index 1023617754..0f154ac684 100644 --- a/integrations/mysql.ini.tmpl +++ b/integrations/mysql.ini.tmpl @@ -10,6 +10,9 @@ PASSWD = {{TEST_MYSQL_PASSWORD}} SSL_MODE = disable PATH = data/gitea.db +[indexer] +ISSUE_INDEXER_PATH = integrations/indexers-mysql/issues.bleve + [repository] ROOT = integrations/gitea-integration-mysql/gitea-repositories diff --git a/integrations/pgsql.ini.tmpl b/integrations/pgsql.ini.tmpl index fa1fd6aa12..301af53b86 100644 --- a/integrations/pgsql.ini.tmpl +++ b/integrations/pgsql.ini.tmpl @@ -10,6 +10,9 @@ PASSWD = {{TEST_PGSQL_PASSWORD}} SSL_MODE = disable PATH = data/gitea.db +[indexer] +ISSUE_INDEXER_PATH = integrations/indexers-pgsql/issues.bleve + [repository] ROOT = integrations/gitea-integration-pgsql/gitea-repositories diff --git a/integrations/sqlite.ini b/integrations/sqlite.ini index ae431a0ac3..9dd38cc6e3 100644 --- a/integrations/sqlite.ini +++ b/integrations/sqlite.ini @@ -5,6 +5,9 @@ RUN_MODE = prod DB_TYPE = sqlite3 PATH = :memory: +[indexer] +ISSUE_INDEXER_PATH = integrations/indexers-sqlite/issues.bleve + [repository] ROOT = integrations/gitea-integration-sqlite/gitea-repositories |