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>
This commit is contained in:
parent
884173232f
commit
55cd33e124
|
@ -66,8 +66,6 @@ coverage.all
|
||||||
/integrations/pgsql.ini
|
/integrations/pgsql.ini
|
||||||
/integrations/mssql.ini
|
/integrations/mssql.ini
|
||||||
/node_modules
|
/node_modules
|
||||||
/modules/indexer/issues/indexers
|
|
||||||
routers/repo/authorized_keys
|
|
||||||
/yarn.lock
|
/yarn.lock
|
||||||
/public/js
|
/public/js
|
||||||
/public/css
|
/public/css
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
package code
|
package code
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -23,15 +23,24 @@ func TestMain(m *testing.M) {
|
||||||
func TestIndexAndSearch(t *testing.T) {
|
func TestIndexAndSearch(t *testing.T) {
|
||||||
models.PrepareTestEnv(t)
|
models.PrepareTestEnv(t)
|
||||||
|
|
||||||
dir := "./bleve.index"
|
dir, err := ioutil.TempDir("", "bleve.index")
|
||||||
os.RemoveAll(dir)
|
assert.NoError(t, err)
|
||||||
|
if err != nil {
|
||||||
|
assert.Fail(t, "Unable to create temporary directory")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
setting.Indexer.RepoIndexerEnabled = true
|
setting.Indexer.RepoIndexerEnabled = true
|
||||||
idx, _, err := NewBleveIndexer(dir)
|
idx, _, err := NewBleveIndexer(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
idx.Close()
|
assert.Fail(t, "Unable to create indexer Error: %v", err)
|
||||||
log.Fatal("indexer.Init: %v", err)
|
if idx != nil {
|
||||||
|
idx.Close()
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
defer idx.Close()
|
||||||
|
|
||||||
err = idx.Index(1)
|
err = idx.Index(1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
"github.com/blevesearch/bleve"
|
"github.com/blevesearch/bleve"
|
||||||
"github.com/blevesearch/bleve/analysis/analyzer/custom"
|
"github.com/blevesearch/bleve/analysis/analyzer/custom"
|
||||||
"github.com/blevesearch/bleve/analysis/token/lowercase"
|
"github.com/blevesearch/bleve/analysis/token/lowercase"
|
||||||
|
@ -184,6 +185,15 @@ func (b *BleveIndexer) Init() (bool, error) {
|
||||||
return false, err
|
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
|
// Index will save the index data
|
||||||
func (b *BleveIndexer) Index(issues []*IndexerData) error {
|
func (b *BleveIndexer) Index(issues []*IndexerData) error {
|
||||||
batch := rupture.NewFlushingBatch(b.indexer, maxBatchSize)
|
batch := rupture.NewFlushingBatch(b.indexer, maxBatchSize)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
package issues
|
package issues
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -12,12 +13,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBleveIndexAndSearch(t *testing.T) {
|
func TestBleveIndexAndSearch(t *testing.T) {
|
||||||
dir := "./bleve.index"
|
dir, err := ioutil.TempDir("", "bleve.index")
|
||||||
indexer := NewBleveIndexer(dir)
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
_, err := indexer.Init()
|
|
||||||
assert.NoError(t, err)
|
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()
|
||||||
|
|
||||||
|
if _, err := indexer.Init(); err != nil {
|
||||||
|
assert.Fail(t, "Unable to initialise bleve indexer: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err = indexer.Index([]*IndexerData{
|
err = indexer.Index([]*IndexerData{
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
package issues
|
package issues
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -23,10 +25,29 @@ func TestMain(m *testing.M) {
|
||||||
func TestBleveSearchIssues(t *testing.T) {
|
func TestBleveSearchIssues(t *testing.T) {
|
||||||
assert.NoError(t, models.PrepareTestDatabase())
|
assert.NoError(t, models.PrepareTestDatabase())
|
||||||
|
|
||||||
os.RemoveAll(setting.Indexer.IssueQueueDir)
|
tmpIndexerDir, err := ioutil.TempDir("", "issues-indexer")
|
||||||
os.RemoveAll(setting.Indexer.IssuePath)
|
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"
|
setting.Indexer.IssueType = "bleve"
|
||||||
InitIssueIndexer(true)
|
InitIssueIndexer(true)
|
||||||
|
defer func() {
|
||||||
|
indexer := holder.get()
|
||||||
|
if bleveIndexer, ok := indexer.(*BleveIndexer); ok {
|
||||||
|
bleveIndexer.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
|
@ -45,6 +66,7 @@ func TestBleveSearchIssues(t *testing.T) {
|
||||||
ids, err = SearchIssuesByKeyword([]int64{1}, "good")
|
ids, err = SearchIssuesByKeyword([]int64{1}, "good")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, []int64{1}, ids)
|
assert.EqualValues(t, []int64{1}, ids)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDBSearchIssues(t *testing.T) {
|
func TestDBSearchIssues(t *testing.T) {
|
||||||
|
|
|
@ -5,18 +5,42 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/auth"
|
"code.gitea.io/gitea/modules/auth"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/test"
|
"code.gitea.io/gitea/modules/test"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestAddReadOnlyDeployKey(t *testing.T) {
|
||||||
|
if deferable := createSSHAuthorizedKeysTmpPath(t); deferable != nil {
|
||||||
|
defer deferable()
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
models.PrepareTestEnv(t)
|
models.PrepareTestEnv(t)
|
||||||
|
|
||||||
ctx := test.MockContext(t, "user2/repo1/settings/keys")
|
ctx := test.MockContext(t, "user2/repo1/settings/keys")
|
||||||
|
@ -39,6 +63,12 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddReadWriteOnlyDeployKey(t *testing.T) {
|
func TestAddReadWriteOnlyDeployKey(t *testing.T) {
|
||||||
|
if deferable := createSSHAuthorizedKeysTmpPath(t); deferable != nil {
|
||||||
|
defer deferable()
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
models.PrepareTestEnv(t)
|
models.PrepareTestEnv(t)
|
||||||
|
|
||||||
ctx := test.MockContext(t, "user2/repo1/settings/keys")
|
ctx := test.MockContext(t, "user2/repo1/settings/keys")
|
||||||
|
|
Loading…
Reference in New Issue