2025-01-31 13:43:55 +00:00
|
|
|
package migrations_test
|
2024-12-24 18:11:25 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"os"
|
|
|
|
|
"path"
|
2025-03-05 12:05:46 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
"queryorchestration/internal/database/migrations"
|
2025-02-05 12:52:41 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
|
|
|
|
"queryorchestration/internal/serviceconfig/database"
|
2025-01-10 19:17:20 +00:00
|
|
|
"queryorchestration/internal/test"
|
2025-01-08 18:14:15 +00:00
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2025-03-19 11:54:14 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2024-12-24 18:11:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestRunMigrations(t *testing.T) {
|
2025-01-17 12:00:32 +00:00
|
|
|
if testing.Short() {
|
|
|
|
|
t.Skip("Skipping long test in short mode")
|
|
|
|
|
}
|
2024-12-24 18:11:25 +00:00
|
|
|
ctx := context.Background()
|
2025-01-10 19:17:20 +00:00
|
|
|
|
2025-02-05 12:52:41 +00:00
|
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
|
|
|
test.SetCfgProvider(t, cfg)
|
|
|
|
|
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
2024-12-24 18:11:25 +00:00
|
|
|
|
2025-01-31 13:43:55 +00:00
|
|
|
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
|
|
|
|
Cfg: cfg,
|
2025-01-08 18:14:15 +00:00
|
|
|
})
|
2025-01-31 13:43:55 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
2025-02-03 17:30:50 +00:00
|
|
|
err := migrations.Run(ctx, cfg)
|
2025-03-19 11:54:14 +00:00
|
|
|
require.NoError(t, err)
|
2025-01-08 18:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRunMigrationsNoDB(t *testing.T) {
|
2025-01-10 19:17:20 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
2025-02-05 12:52:41 +00:00
|
|
|
cfg := &serviceconfig.BaseConfig{}
|
|
|
|
|
test.SetCfgProvider(t, cfg)
|
|
|
|
|
cfg.SetBasePath(path.Join(os.Getenv("PWD"), "../../.."))
|
|
|
|
|
cfg.SetDBConfig(&database.DBConfig{
|
|
|
|
|
DBUser: "invalid_user",
|
|
|
|
|
DBSecret: "invalid_pass",
|
|
|
|
|
DBHost: "invalid_host",
|
|
|
|
|
DBPort: 5432,
|
|
|
|
|
DBName: "invalid_name",
|
|
|
|
|
DBNoSSL: true,
|
|
|
|
|
})
|
2025-02-03 17:30:50 +00:00
|
|
|
|
|
|
|
|
err := migrations.Run(ctx, cfg)
|
2025-01-31 13:43:55 +00:00
|
|
|
assert.Error(t, err)
|
2024-12-24 18:11:25 +00:00
|
|
|
}
|