2020-08-30 19:08:01 +03:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 21:20:29 +03:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-08-30 19:08:01 +03:00
|
|
|
|
|
|
|
package code
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-12 17:36:47 +03:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
|
|
|
2020-08-30 19:08:01 +03:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestESIndexAndSearch(t *testing.T) {
|
2021-11-12 17:36:47 +03:00
|
|
|
unittest.PrepareTestEnv(t)
|
2020-08-30 19:08:01 +03:00
|
|
|
|
|
|
|
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 15:31:52 +03:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|