2025-03-20 11:06:41 +00:00
|
|
|
package database_test
|
2024-12-24 18:11:25 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-03-05 12:05:46 +00:00
|
|
|
"testing"
|
|
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
migrations "queryorchestration/internal/database"
|
2025-02-05 12:52:41 +00:00
|
|
|
"queryorchestration/internal/serviceconfig"
|
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)
|
2024-12-24 18:11:25 +00:00
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
_, cleanup := test.CreateDB(t, ctx, cfg, &test.CreateDatabaseConfig{})
|
2025-01-31 13:43:55 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
err := migrations.RunMigrations(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)
|
2025-04-02 18:50:03 +00:00
|
|
|
cfg.SetDBUser("invalid_user")
|
|
|
|
|
cfg.SetDBSecret("invalid_pass")
|
|
|
|
|
cfg.SetDBHost("invalid_host")
|
|
|
|
|
cfg.SetDBPort(5432)
|
|
|
|
|
cfg.SetDBName("invalid_name")
|
|
|
|
|
cfg.SetDBNoSSL(true)
|
2025-02-03 17:30:50 +00:00
|
|
|
|
2025-03-20 11:06:41 +00:00
|
|
|
err := migrations.RunMigrations(ctx, cfg)
|
2025-01-31 13:43:55 +00:00
|
|
|
assert.Error(t, err)
|
2024-12-24 18:11:25 +00:00
|
|
|
}
|