2019-02-20 19:54:05 -05:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package issues
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
models.MainTest(m, filepath.Join("..", "..", ".."))
|
|
|
|
}
|
|
|
|
|
2019-02-24 11:16:20 -05:00
|
|
|
func TestBleveSearchIssues(t *testing.T) {
|
2019-02-20 19:54:05 -05:00
|
|
|
assert.NoError(t, models.PrepareTestDatabase())
|
|
|
|
|
2019-04-08 04:05:15 -05:00
|
|
|
os.RemoveAll(setting.Indexer.IssueQueueDir)
|
2019-02-20 19:54:05 -05:00
|
|
|
os.RemoveAll(setting.Indexer.IssuePath)
|
2019-02-24 11:16:20 -05:00
|
|
|
setting.Indexer.IssueType = "bleve"
|
2019-10-15 08:39:51 -05:00
|
|
|
InitIssueIndexer(true)
|
2019-02-20 19:54:05 -05:00
|
|
|
|
2019-02-24 11:16:20 -05:00
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
|
|
|
|
ids, err := SearchIssuesByKeyword(1, "issue2")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, []int64{2}, ids)
|
|
|
|
|
|
|
|
ids, err = SearchIssuesByKeyword(1, "first")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, []int64{1}, ids)
|
|
|
|
|
|
|
|
ids, err = SearchIssuesByKeyword(1, "for")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, []int64{1, 2, 3, 5}, ids)
|
|
|
|
|
|
|
|
ids, err = SearchIssuesByKeyword(1, "good")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, []int64{1}, ids)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDBSearchIssues(t *testing.T) {
|
|
|
|
assert.NoError(t, models.PrepareTestDatabase())
|
|
|
|
|
|
|
|
setting.Indexer.IssueType = "db"
|
2019-10-15 08:39:51 -05:00
|
|
|
InitIssueIndexer(true)
|
2019-02-20 19:54:05 -05:00
|
|
|
|
|
|
|
ids, err := SearchIssuesByKeyword(1, "issue2")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, []int64{2}, ids)
|
|
|
|
|
|
|
|
ids, err = SearchIssuesByKeyword(1, "first")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, []int64{1}, ids)
|
|
|
|
|
|
|
|
ids, err = SearchIssuesByKeyword(1, "for")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, []int64{1, 2, 3, 5}, ids)
|
2019-02-21 00:01:28 -05:00
|
|
|
|
|
|
|
ids, err = SearchIssuesByKeyword(1, "good")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, []int64{1}, ids)
|
2019-02-20 19:54:05 -05:00
|
|
|
}
|