2024-12-24 18:11:25 +00:00
|
|
|
package database_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"queryorchestration/internal/database"
|
2025-01-10 19:17:20 +00:00
|
|
|
"queryorchestration/internal/test"
|
2024-12-24 18:11:25 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestDBConn(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
2025-01-10 19:17:20 +00:00
|
|
|
_, cleanup := test.CreateDB(t, ctx, &test.CreateDatabaseConfig{
|
|
|
|
|
Migrations: &database.MigrationConfig{
|
|
|
|
|
BasePath: "../..",
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-01-10 11:12:03 +00:00
|
|
|
defer cleanup()
|
2024-12-24 18:11:25 +00:00
|
|
|
|
|
|
|
|
conn := database.GetDBConn(ctx)
|
|
|
|
|
assert.NotNil(t, conn)
|
2025-01-10 19:17:20 +00:00
|
|
|
|
|
|
|
|
pool := database.GetDBPool(ctx)
|
|
|
|
|
assert.NotNil(t, pool)
|
2025-01-08 18:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestDBConnNoDB(t *testing.T) {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
t.Setenv("DB_USER", "user")
|
|
|
|
|
t.Setenv("DB_PASS", "pass")
|
|
|
|
|
t.Setenv("DB_HOST", "host")
|
|
|
|
|
t.Setenv("DB_PORT", "5432")
|
|
|
|
|
t.Setenv("DB_NAME", "name")
|
2024-12-24 18:11:25 +00:00
|
|
|
|
|
|
|
|
assert.Panics(t, func() { database.GetDBConn(ctx) })
|
|
|
|
|
}
|