/integrations/pgsql.ini
/integrations/mssql.ini
/node_modules
-/modules/indexer/issues/indexers
-routers/repo/authorized_keys
/yarn.lock
/public/js
/public/css
package code
import (
+ "io/ioutil"
"os"
"path/filepath"
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
func TestIndexAndSearch(t *testing.T) {
models.PrepareTestEnv(t)
- dir := "./bleve.index"
- os.RemoveAll(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)
setting.Indexer.RepoIndexerEnabled = true
idx, _, err := NewBleveIndexer(dir)
if err != nil {
- idx.Close()
- log.Fatal("indexer.Init: %v", err)
+ assert.Fail(t, "Unable to create indexer Error: %v", err)
+ if idx != nil {
+ idx.Close()
+ }
+ return
}
+ defer idx.Close()
err = idx.Index(1)
assert.NoError(t, err)
"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"
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)
package issues
import (
+ "io/ioutil"
"os"
"testing"
)
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{
{
package issues
import (
+ "io/ioutil"
"os"
+ "path"
"path/filepath"
"testing"
"time"
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)
ids, err = SearchIssuesByKeyword([]int64{1}, "good")
assert.NoError(t, err)
assert.EqualValues(t, []int64{1}, ids)
+
}
func TestDBSearchIssues(t *testing.T) {
package repo
import (
+ "io/ioutil"
"net/http"
+ "os"
"testing"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
"github.com/stretchr/testify/assert"
)
+func createSSHAuthorizedKeysTmpPath(t *testing.T) func() {
+ tmpDir, err := ioutil.TempDir("", "tmp-ssh")
+ if err != nil {
+ assert.Fail(t, "Unable to create temporary directory: %v", err)
+ return nil
+ }
+
+ oldPath := setting.SSH.RootPath
+ setting.SSH.RootPath = tmpDir
+
+ return func() {
+ setting.SSH.RootPath = oldPath
+ os.RemoveAll(tmpDir)
+ }
+}
+
func TestAddReadOnlyDeployKey(t *testing.T) {
+ if deferable := createSSHAuthorizedKeysTmpPath(t); deferable != nil {
+ defer deferable()
+ } else {
+ return
+ }
models.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/settings/keys")
}
func TestAddReadWriteOnlyDeployKey(t *testing.T) {
+ if deferable := createSSHAuthorizedKeysTmpPath(t); deferable != nil {
+ defer deferable()
+ } else {
+ return
+ }
+
models.PrepareTestEnv(t)
ctx := test.MockContext(t, "user2/repo1/settings/keys")