diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-03 07:26:39 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-10-03 07:26:39 +0200 |
commit | f6da362f94622d1c0d09d1fdbef84997ad8dc7c0 (patch) | |
tree | 044624ec4342cef42b237773578910f14594af0c /planetwars-server/tests | |
parent | 8f6b34db10c591507271845150314be7a07cee19 (diff) | |
download | planetwars.dev-f6da362f94622d1c0d09d1fdbef84997ad8dc7c0.tar.xz planetwars.dev-f6da362f94622d1c0d09d1fdbef84997ad8dc7c0.zip |
clear database between test runs
Diffstat (limited to 'planetwars-server/tests')
-rw-r--r-- | planetwars-server/tests/integration.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/planetwars-server/tests/integration.rs b/planetwars-server/tests/integration.rs index 29589ad..487a25e 100644 --- a/planetwars-server/tests/integration.rs +++ b/planetwars-server/tests/integration.rs @@ -2,6 +2,7 @@ use axum::{ body::Body, http::{self, Request, StatusCode}, }; +use diesel::{PgConnection, RunQueryDsl}; use planetwars_server::{create_db_pool, create_pw_api, GlobalConfig}; use serde_json::{self, json, Value as JsonValue}; use std::{io, path::Path, sync::Arc}; @@ -19,7 +20,23 @@ fn create_subdir<P: AsRef<Path>>(base_path: &Path, p: P) -> io::Result<String> { Ok(dir_path_string) } -#[tokio::test] +fn clear_database(conn: &PgConnection) { + diesel::sql_query( + "TRUNCATE TABLE + bots, + bot_versions, + maps, + matches, + match_players, + ratings, + sessions, + users", + ) + .execute(conn) + .expect("failed to clear database"); +} + +#[tokio::test(flavor = "multi_thread")] async fn test_application() -> io::Result<()> { let _db_guard = DB_LOCK.lock(); let data_dir = TempDir::new().expect("failed to create temp dir"); @@ -36,6 +53,10 @@ async fn test_application() -> io::Result<()> { ranker_enabled: false, }); let db_pool = create_db_pool(&config).await; + { + let db_conn = db_pool.get().await.expect("failed to get db connection"); + clear_database(&db_conn); + } let app = create_pw_api(config, db_pool); let response = app |