veza/veza-backend-api/internal/elasticsearch/search_service_test.go

44 lines
1.1 KiB
Go
Raw Normal View History

package elasticsearch
import (
"testing"
"go.uber.org/zap"
)
func TestSearchService_Search_NilClient(t *testing.T) {
svc := NewSearchService(nil, zap.NewNop())
_, err := svc.Search("test", nil, nil)
if err == nil {
t.Fatal("expected error when client is nil")
}
if err.Error() != "elasticsearch client not configured" {
t.Errorf("unexpected error: %v", err)
}
}
func TestSearchService_Suggestions_NilClient(t *testing.T) {
svc := NewSearchService(nil, zap.NewNop())
_, err := svc.Suggestions("test", 5)
if err == nil {
t.Fatal("expected error when client is nil")
}
}
func TestLoadConfig(t *testing.T) {
cfg := LoadConfig()
// When ELASTICSEARCH_INDEX unset, default is veza-platform
if cfg.Index == "" {
t.Error("index should not be empty (default veza-platform)")
}
}
func TestIndexName(t *testing.T) {
if got := indexName("veza-platform", "tracks"); got != "veza-platform-tracks" {
t.Errorf("indexName = %q, want veza-platform-tracks", got)
}
if got := indexName("", "tracks"); got != "veza-tracks" {
t.Errorf("indexName = %q, want veza-tracks", got)
}
}