diff options
| author | Joe Carstairs <me@joeac.net> | 2024-11-30 22:50:17 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-11-30 22:51:25 +0000 |
| commit | 48973ceda54950c4da11b131108f642a5df48dce (patch) | |
| tree | 62fa393f8b20967f6bbe7fb75cef87fbbee14f90 /rust/actualbudget_to_schist_transformer/tests/common/test_context.rs | |
| parent | 283475af457c71db280fe7732218450a3163614b (diff) | |
Integration test for AB transformer
Diffstat (limited to 'rust/actualbudget_to_schist_transformer/tests/common/test_context.rs')
| -rw-r--r-- | rust/actualbudget_to_schist_transformer/tests/common/test_context.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/rust/actualbudget_to_schist_transformer/tests/common/test_context.rs b/rust/actualbudget_to_schist_transformer/tests/common/test_context.rs new file mode 100644 index 0000000..e59c5f8 --- /dev/null +++ b/rust/actualbudget_to_schist_transformer/tests/common/test_context.rs @@ -0,0 +1,42 @@ +use anyhow::Context; +use diesel::{Connection, SqliteConnection}; +use diesel_migrations::MigrationHarness; +use schist_queries::clear::clear; +use schist_models::migrations::MIGRATIONS; + +use super::{TEST_IN_DB_URL, TEST_OUT_DB_URL}; + +pub struct TestContext { +} + +impl TestContext { + pub fn new() -> Self { + let _in_connection = &mut SqliteConnection + ::establish(&TEST_IN_DB_URL) + .with_context(|| format!("failed to establish connection to in database at {}", TEST_IN_DB_URL)) + .unwrap(); + + let out_connection = &mut SqliteConnection + ::establish(&TEST_OUT_DB_URL) + .with_context(|| format!("failed to establish connection to out database at {}", TEST_OUT_DB_URL)) + .unwrap(); + + out_connection + .run_pending_migrations(MIGRATIONS) + .expect("failed to run migrations on out database"); + + clear(out_connection) + .expect("failed to clear database"); + + Self { + } + } +} + +impl Drop for TestContext { + fn drop(&mut self) { + std::fs::remove_file(&TEST_OUT_DB_URL) + .with_context(|| format!("failed to delete out database at {}", TEST_OUT_DB_URL)) + .unwrap(); + } +} |
