Files
temporal/schema/embed_test.go
Rob Holland 389d1ab7d1 Fix command line flag argument parsing for elasticsearch-tool. (#8445)
## What changed?
Reverts to urlfav/cli v1 as per other tools and uses shared flag aliases
where appropriate for more consistency with the other tools.

Works around Go embed's lack of support for symlinks by hard coding the
path to the index template to use. Adds a test to ensure this doesn't
get out of sync with the latest.

## Why?
Better consistency with other tools and being able to actually find the
index template :)

## How did you test it?
- [x] built
- [x] run locally and tested manually
- [ ] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)
2025-10-08 07:49:42 +01:00

57 lines
1.5 KiB
Go

package schema
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
)
func TestSchemaDirs(t *testing.T) {
dirs := PathsByDir("cassandra")
requireContains(t, []string{
"cassandra/temporal",
}, dirs)
dirs = PathsByDir("mysql")
requireContains(t, []string{
"mysql/v8/temporal",
"mysql/v8/visibility",
}, dirs)
dirs = PathsByDir("postgresql")
requireContains(t, []string{
"postgresql/v12/temporal",
"postgresql/v12/visibility",
}, dirs)
}
func TestElasticsearchIndexTemplateIsLatest(t *testing.T) {
embeddedContent, err := ElasticsearchIndexTemplate()
require.NoError(t, err, "Failed to get embedded index template")
symlinkPath := "elasticsearch/visibility/index_template_v7.json"
symlinkInfo, err := os.Lstat(symlinkPath)
require.NoError(t, err, "Failed to get symlink info")
require.True(t, symlinkInfo.Mode()&os.ModeSymlink != 0, "File is not a symlink")
targetPath, err := os.Readlink(symlinkPath)
require.NoError(t, err, "Failed to read symlink target")
fullTargetPath := filepath.Join(filepath.Dir(symlinkPath), targetPath)
targetContent, err := os.ReadFile(fullTargetPath)
require.NoError(t, err, "Failed to read symlink target file")
require.Equal(t, string(targetContent), embeddedContent,
"Embedded content does not match symlink target. "+
"Symlink points to: %s. "+
"Update the ElasticsearchIndexTemplate() function to use the correct path.", targetPath)
}
func requireContains(t *testing.T, expected []string, actual []string) {
for _, v := range expected {
require.Contains(t, actual, v)
}
}