aboutsummaryrefslogtreecommitdiffstats
path: root/modules/indexer/code/indexer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/indexer/code/indexer_test.go')
-rw-r--r--modules/indexer/code/indexer_test.go50
1 files changed, 48 insertions, 2 deletions
diff --git a/modules/indexer/code/indexer_test.go b/modules/indexer/code/indexer_test.go
index 52f7e76e41..55616a0361 100644
--- a/modules/indexer/code/indexer_test.go
+++ b/modules/indexer/code/indexer_test.go
@@ -5,11 +5,15 @@ package code
import (
"context"
+ "os"
"path/filepath"
"testing"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/indexer/code/bleve"
+ "code.gitea.io/gitea/modules/indexer/code/elasticsearch"
+ "code.gitea.io/gitea/modules/indexer/code/internal"
_ "code.gitea.io/gitea/models"
@@ -22,7 +26,7 @@ func TestMain(m *testing.M) {
})
}
-func testIndexer(name string, t *testing.T, indexer Indexer) {
+func testIndexer(name string, t *testing.T, indexer internal.Indexer) {
t.Run(name, func(t *testing.T) {
var repoID int64 = 1
err := index(git.DefaultContext, indexer, repoID)
@@ -81,6 +85,48 @@ func testIndexer(name string, t *testing.T, indexer Indexer) {
})
}
- assert.NoError(t, indexer.Delete(repoID))
+ assert.NoError(t, indexer.Delete(context.Background(), repoID))
})
}
+
+func TestBleveIndexAndSearch(t *testing.T) {
+ unittest.PrepareTestEnv(t)
+
+ dir := t.TempDir()
+
+ idx := bleve.NewIndexer(dir)
+ _, err := idx.Init(context.Background())
+ if err != nil {
+ assert.Fail(t, "Unable to create bleve indexer Error: %v", err)
+ if idx != nil {
+ idx.Close()
+ }
+ return
+ }
+ defer idx.Close()
+
+ testIndexer("beleve", t, idx)
+}
+
+func TestESIndexAndSearch(t *testing.T) {
+ unittest.PrepareTestEnv(t)
+
+ u := os.Getenv("TEST_INDEXER_CODE_ES_URL")
+ if u == "" {
+ t.SkipNow()
+ return
+ }
+
+ indexer := elasticsearch.NewIndexer(u, "gitea_codes")
+ if _, err := indexer.Init(context.Background()); err != nil {
+ assert.Fail(t, "Unable to init ES indexer Error: %v", err)
+ if indexer != nil {
+ indexer.Close()
+ }
+ return
+ }
+
+ defer indexer.Close()
+
+ testIndexer("elastic_search", t, indexer)
+}