From 48973ceda54950c4da11b131108f642a5df48dce Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Sat, 30 Nov 2024 22:50:17 +0000 Subject: Integration test for AB transformer --- .../tests/common/test_context.rs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 rust/actualbudget_to_schist_transformer/tests/common/test_context.rs (limited to 'rust/actualbudget_to_schist_transformer/tests/common/test_context.rs') 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(); + } +} -- cgit v1.2.3