fa95d733ca
Add short tests and Tidy internal directories * complete the tasks
44 lines
947 B
Go
44 lines
947 B
Go
package database_test
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path"
|
|
"queryorchestration/internal/database"
|
|
"queryorchestration/internal/test"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRunMigrations(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skip("Skipping long test in short mode")
|
|
}
|
|
ctx := context.Background()
|
|
|
|
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{})
|
|
defer cleanup()
|
|
|
|
database.RunMigrations(ctx, &database.MigrationConfig{
|
|
BasePath: path.Join(os.Getenv("PWD"), "../.."),
|
|
})
|
|
}
|
|
|
|
func TestRunMigrationsNoDB(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
t.Setenv("DB_USER", "invalid_user")
|
|
t.Setenv("DB_PASS", "invalid_pass")
|
|
t.Setenv("DB_HOST", "invalid_host")
|
|
t.Setenv("DB_PORT", "5432")
|
|
t.Setenv("DB_NAME", "invalid_name")
|
|
t.Setenv("DB_NOSSL", "1")
|
|
|
|
assert.Panics(t, func() {
|
|
database.RunMigrations(ctx, &database.MigrationConfig{
|
|
BasePath: path.Join(os.Getenv("PWD"), "../.."),
|
|
})
|
|
})
|
|
}
|