Skip to content

Commit f0937e7

Browse files
committed
fix: add tests containers
1 parent 8abd968 commit f0937e7

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

.idea/runConfigurations/Run_tests_without_docker.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ async-trait = "0.1.0"
4343
serde_test = "1.0"
4444
tracing-test = "0.1"
4545
tokio-test = "0.4"
46+
testcontainers = "0.12"
4647

4748
[features]
4849
default = ["postgres"]
50+
disable-docker = []
4951

5052
postgres = ["sqlx/postgres"]
5153
mysql = ["sqlx/mysql"]

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,24 @@ async fn setup_database(db: &str) -> Result<PgPool, sqlx::Error> {
8686
info!("Ran migration");
8787
Ok(pool)
8888
}
89+
90+
#[cfg(test)]
91+
mod tests {
92+
use testcontainers::*;
93+
94+
use super::setup_database;
95+
96+
#[cfg(not(feature = "disable-docker"))]
97+
#[tokio::test]
98+
async fn test_setup_database() {
99+
let docker = clients::Cli::default();
100+
let node = docker.run(images::postgres::Postgres::default());
101+
102+
let connection_string = &format!(
103+
"postgres://postgres:postgres@localhost:{}/postgres",
104+
node.get_host_port(5432).unwrap()
105+
);
106+
107+
let _pool = setup_database(connection_string).await.unwrap();
108+
}
109+
}

0 commit comments

Comments
 (0)