2025-01-10 11:12:03 +00:00
|
|
|
package server_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-01-31 13:43:55 +00:00
|
|
|
"fmt"
|
2025-01-14 17:28:26 +00:00
|
|
|
"os"
|
|
|
|
|
"path"
|
2025-03-05 12:05:46 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-01-10 11:12:03 +00:00
|
|
|
"queryorchestration/internal/server"
|
2025-01-10 19:17:20 +00:00
|
|
|
"queryorchestration/internal/test"
|
2025-01-10 11:12:03 +00:00
|
|
|
|
2025-02-07 12:12:51 +00:00
|
|
|
"github.com/go-playground/validator/v10"
|
2025-01-10 11:12:03 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestNew(t *testing.T) {
|
2025-01-17 12:00:32 +00:00
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
2025-01-10 11:12:03 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2025-02-05 12:52:41 +00:00
|
|
|
cfg := &server.BaseConfig{}
|
|
|
|
|
test.SetCfgProvider(t, cfg)
|
|
|
|
|
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../.."))
|
2025-01-10 11:12:03 +00:00
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
|
|
|
|
Cfg: cfg,
|
|
|
|
|
})
|
|
|
|
|
defer cleanup()
|
2025-01-10 11:12:03 +00:00
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
clean, err := server.New(ctx, cfg)
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := clean(); err != nil {
|
|
|
|
|
// Log cleanup error but don't panic since we're shutting down
|
|
|
|
|
fmt.Printf("Error during clean: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
2025-01-10 11:12:03 +00:00
|
|
|
}
|
2025-02-07 12:12:51 +00:00
|
|
|
|
|
|
|
|
func TestSetValidator(t *testing.T) {
|
|
|
|
|
cfg := server.BaseConfig{}
|
|
|
|
|
|
|
|
|
|
assert.Nil(t, cfg.Validator)
|
|
|
|
|
|
|
|
|
|
cfg.SetValidator()
|
|
|
|
|
assert.NotNil(t, cfg.Validator)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestGetValidator(t *testing.T) {
|
|
|
|
|
cfg := server.BaseConfig{}
|
|
|
|
|
|
|
|
|
|
assert.Nil(t, cfg.GetValidator())
|
|
|
|
|
cfg.Validator = validator.New()
|
|
|
|
|
assert.NotNil(t, cfg.GetValidator())
|
|
|
|
|
assert.EqualExportedValues(t, validator.New(), cfg.GetValidator())
|
|
|
|
|
}
|