2020-08-30 21:38:01 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2020-08-30 21:38:01 +05:30
|
|
|
|
|
|
|
package code
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
|
2020-08-30 21:38:01 +05:30
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestESIndexAndSearch(t *testing.T) {
|
2021-11-12 20:06:47 +05:30
|
|
|
unittest.PrepareTestEnv(t)
|
2020-08-30 21:38:01 +05:30
|
|
|
|
|
|
|
u := os.Getenv("TEST_INDEXER_CODE_ES_URL")
|
|
|
|
if u == "" {
|
|
|
|
t.SkipNow()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
indexer, _, err := NewElasticSearchIndexer(u, "gitea_codes")
|
|
|
|
if err != nil {
|
|
|
|
assert.Fail(t, "Unable to create ES indexer Error: %v", err)
|
|
|
|
if indexer != nil {
|
|
|
|
indexer.Close()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer indexer.Close()
|
|
|
|
|
|
|
|
testIndexer("elastic_search", t, indexer)
|
|
|
|
}
|
2020-09-12 18:01:52 +05:30
|
|
|
|
|
|
|
func TestIndexPos(t *testing.T) {
|
|
|
|
startIdx, endIdx := indexPos("test index start and end", "start", "end")
|
|
|
|
assert.EqualValues(t, 11, startIdx)
|
|
|
|
assert.EqualValues(t, 24, endIdx)
|
|
|
|
}
|