refactor(search): move index management from the osu to the opensearch package

This commit is contained in:
fschade
2025-08-28 09:32:05 +02:00
parent e00fdc6ba3
commit 8d850b1f4a
4 changed files with 11 additions and 11 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ func NewBackend(index string, client *opensearchgoAPI.Client) (*Backend, error)
}
// apply the index template
if err := osu.IndexManagerLatest.Apply(context.TODO(), index, client); err != nil {
if err := IndexManagerLatest.Apply(context.TODO(), index, client); err != nil {
return nil, fmt.Errorf("failed to apply index template: %w", err)
}
@@ -1,4 +1,4 @@
package osu
package opensearch
import (
"bytes"
@@ -20,7 +20,7 @@ var (
IndexIndexManagerResourceV1 IndexManager = "resource_v1.json"
)
//go:embed indexes/*.json
//go:embed internal/indexes/*.json
var indexes embed.FS
type IndexManager string
@@ -36,7 +36,7 @@ func (m IndexManager) String() string {
func (m IndexManager) MarshalJSON() ([]byte, error) {
filePath := string(m)
body, err := indexes.ReadFile(path.Join("./indexes", filePath))
body, err := indexes.ReadFile(path.Join("./internal/indexes", filePath))
switch {
case err != nil:
return nil, fmt.Errorf("failed to read index file %s: %w", filePath, err)
@@ -1,4 +1,4 @@
package osu_test
package opensearch_test
import (
"strings"
@@ -7,16 +7,16 @@ import (
"github.com/stretchr/testify/require"
"github.com/tidwall/sjson"
"github.com/opencloud-eu/opencloud/services/search/pkg/opensearch/internal/osu"
"github.com/opencloud-eu/opencloud/services/search/pkg/opensearch"
opensearchtest "github.com/opencloud-eu/opencloud/services/search/pkg/opensearch/internal/test"
)
func TestIndexManager(t *testing.T) {
t.Run("index plausibility", func(t *testing.T) {
tests := []opensearchtest.TableTest[osu.IndexManager, struct{}]{
tests := []opensearchtest.TableTest[opensearch.IndexManager, struct{}]{
{
Name: "empty",
Got: osu.IndexManagerLatest,
Got: opensearch.IndexManagerLatest,
},
}
tc := opensearchtest.NewDefaultTestClient(t)
@@ -37,7 +37,7 @@ func TestIndexManager(t *testing.T) {
})
t.Run("does not create index if it already exists and is up to date", func(t *testing.T) {
indexManager := osu.IndexManagerLatest
indexManager := opensearch.IndexManagerLatest
indexName := "opencloud-test-resource"
tc := opensearchtest.NewDefaultTestClient(t)
@@ -48,7 +48,7 @@ func TestIndexManager(t *testing.T) {
})
t.Run("fails to create index if it already exists but is not up to date", func(t *testing.T) {
indexManager := osu.IndexManagerLatest
indexManager := opensearch.IndexManagerLatest
indexName := "opencloud-test-resource"
tc := opensearchtest.NewDefaultTestClient(t)
@@ -58,6 +58,6 @@ func TestIndexManager(t *testing.T) {
require.NoError(t, err)
tc.Require.IndicesCreate(indexName, strings.NewReader(body))
require.ErrorIs(t, indexManager.Apply(t.Context(), indexName, tc.Client()), osu.ErrManualActionRequired)
require.ErrorIs(t, indexManager.Apply(t.Context(), indexName, tc.Client()), opensearch.ErrManualActionRequired)
})
}