diff options
author | zeripath <art27@cantab.net> | 2019-12-28 02:08:05 +0000 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-12-28 10:08:05 +0800 |
commit | 55cd33e124e152869fa2f2dc420e6a5be98a3cbe (patch) | |
tree | 85f9b800248c202d024c7b6b6c1dc37243782f58 /modules/indexer/issues | |
parent | 884173232fa036b032f77d5a10d78e695e96b5de (diff) | |
download | gitea-55cd33e124e152869fa2f2dc420e6a5be98a3cbe.tar.gz gitea-55cd33e124e152869fa2f2dc420e6a5be98a3cbe.zip |
Stop various tests from adding to the source tree (#9515)
Instead of just adding test generated files to .gitignore prevent
them from being produced in the first place.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/indexer/issues')
-rw-r--r-- | modules/indexer/issues/bleve.go | 10 | ||||
-rw-r--r-- | modules/indexer/issues/bleve_test.go | 17 | ||||
-rw-r--r-- | modules/indexer/issues/indexer_test.go | 26 |
3 files changed, 47 insertions, 6 deletions
diff --git a/modules/indexer/issues/bleve.go b/modules/indexer/issues/bleve.go index 24443e54a3..787ff0dec5 100644 --- a/modules/indexer/issues/bleve.go +++ b/modules/indexer/issues/bleve.go @@ -9,6 +9,7 @@ import ( "os" "strconv" + "code.gitea.io/gitea/modules/log" "github.com/blevesearch/bleve" "github.com/blevesearch/bleve/analysis/analyzer/custom" "github.com/blevesearch/bleve/analysis/token/lowercase" @@ -184,6 +185,15 @@ func (b *BleveIndexer) Init() (bool, error) { return false, err } +// Close will close the bleve indexer +func (b *BleveIndexer) Close() { + if b.indexer != nil { + if err := b.indexer.Close(); err != nil { + log.Error("Error whilst closing indexer: %v", err) + } + } +} + // Index will save the index data func (b *BleveIndexer) Index(issues []*IndexerData) error { batch := rupture.NewFlushingBatch(b.indexer, maxBatchSize) diff --git a/modules/indexer/issues/bleve_test.go b/modules/indexer/issues/bleve_test.go index 94d935d89d..234da076cd 100644 --- a/modules/indexer/issues/bleve_test.go +++ b/modules/indexer/issues/bleve_test.go @@ -5,6 +5,7 @@ package issues import ( + "io/ioutil" "os" "testing" @@ -12,12 +13,20 @@ import ( ) func TestBleveIndexAndSearch(t *testing.T) { - dir := "./bleve.index" - indexer := NewBleveIndexer(dir) + dir, err := ioutil.TempDir("", "bleve.index") + assert.NoError(t, err) + if err != nil { + assert.Fail(t, "Unable to create temporary directory") + return + } defer os.RemoveAll(dir) + indexer := NewBleveIndexer(dir) + defer indexer.Close() - _, err := indexer.Init() - assert.NoError(t, err) + if _, err := indexer.Init(); err != nil { + assert.Fail(t, "Unable to initialise bleve indexer: %v", err) + return + } err = indexer.Index([]*IndexerData{ { diff --git a/modules/indexer/issues/indexer_test.go b/modules/indexer/issues/indexer_test.go index a45fede9ac..ca7ba29703 100644 --- a/modules/indexer/issues/indexer_test.go +++ b/modules/indexer/issues/indexer_test.go @@ -5,7 +5,9 @@ package issues import ( + "io/ioutil" "os" + "path" "path/filepath" "testing" "time" @@ -23,10 +25,29 @@ func TestMain(m *testing.M) { func TestBleveSearchIssues(t *testing.T) { assert.NoError(t, models.PrepareTestDatabase()) - os.RemoveAll(setting.Indexer.IssueQueueDir) - os.RemoveAll(setting.Indexer.IssuePath) + tmpIndexerDir, err := ioutil.TempDir("", "issues-indexer") + if err != nil { + assert.Fail(t, "Unable to create temporary directory: %v", err) + return + } + oldQueueDir := setting.Indexer.IssueQueueDir + oldIssuePath := setting.Indexer.IssuePath + setting.Indexer.IssueQueueDir = path.Join(tmpIndexerDir, "issues.queue") + setting.Indexer.IssuePath = path.Join(tmpIndexerDir, "issues.queue") + defer func() { + setting.Indexer.IssueQueueDir = oldQueueDir + setting.Indexer.IssuePath = oldIssuePath + os.RemoveAll(tmpIndexerDir) + }() + setting.Indexer.IssueType = "bleve" InitIssueIndexer(true) + defer func() { + indexer := holder.get() + if bleveIndexer, ok := indexer.(*BleveIndexer); ok { + bleveIndexer.Close() + } + }() time.Sleep(5 * time.Second) @@ -45,6 +66,7 @@ func TestBleveSearchIssues(t *testing.T) { ids, err = SearchIssuesByKeyword([]int64{1}, "good") assert.NoError(t, err) assert.EqualValues(t, []int64{1}, ids) + } func TestDBSearchIssues(t *testing.T) { |