I'm currently using the following helper in my tests.
I'm seeing the error ConnectionUnavailable when I run it now. only in one test. I guess the problems is I start the pool per test.
Is there a way to have a transaction per test but not a pool? is that the right approach to db testing? Does anyone have an example that's public?
pub fn test_context(then) {
// Only the db service should be accessed during tests
let assert Ok(postgres_password) = envoy.get("POSTGRES_PASSWORD")
let config =
config.Config(
postgres_pool_name: process.new_name("postgres_pool"),
postgres_password:,
)
let assert Ok(context) = context.from_config(config)
let assert Ok(conn) = pool.start(config)
let assert Error(pog.TransactionRolledBack(Nil)) =
pog.transaction(conn.data, fn(db) {
let ai = process.new_subject()
let context = context.Context(..context, db:, ai:)
then(context, ai)
Error(Nil)
})
}