initial-commit

This commit is contained in:
Guillaume GRABÉ
2026-05-12 17:06:43 +02:00
commit 051a080dfa
110 changed files with 26377 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
use charybdis::database::{EntityRepository, ensure_schema};
use sqlx::PgPool;
use testcontainers::runners::AsyncRunner;
use testcontainers_modules::postgres::Postgres;
pub struct TestDb {
pub pool: PgPool,
pub repository: EntityRepository,
_container: testcontainers::ContainerAsync<Postgres>,
}
impl TestDb {
pub async fn new() -> Self {
// Testcontainers picks up DOCKER_HOST or TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE
// For Colima users: export DOCKER_HOST=unix:///Users/$USER/.colima/default/docker.sock
let container = Postgres::default().start().await.unwrap();
let port = container.get_host_port_ipv4(5432).await.unwrap();
let url = format!("postgresql://postgres:postgres@127.0.0.1:{}/postgres", port);
let pool = PgPool::connect(&url).await.unwrap();
ensure_schema(&pool).await.unwrap();
let repository = EntityRepository::new(pool.clone());
Self {
pool,
repository,
_container: container,
}
}
}