You've already forked AstralRinth
forked from didirus/AstralRinth
Batch inserts [MOD-555] (#726)
* Batch a bunch of inserts, but still more to do * Insert many for clickhouse (+ tests) * Batch the remaining ones except those requiring deduplication * Risky dedups * Bit o cleanup and formatting * cargo sqlx prepare * Add test around batch editing project categories * Add struct to satisfy clippy * Fix silly mistake that was caught by the tests! * Leave room for growth in dummy_data
This commit is contained in:
@@ -29,6 +29,7 @@ pub const USER_USER_PAT: &str = "mrp_patuser";
|
||||
pub const FRIEND_USER_PAT: &str = "mrp_patfriend";
|
||||
pub const ENEMY_USER_PAT: &str = "mrp_patenemy";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TemporaryDatabase {
|
||||
pub pool: PgPool,
|
||||
pub redis_pool: RedisPool,
|
||||
@@ -75,10 +76,14 @@ impl TemporaryDatabase {
|
||||
.await
|
||||
.expect("Connection to temporary database failed");
|
||||
|
||||
println!("Running migrations on temporary database");
|
||||
|
||||
// Performs migrations
|
||||
let migrations = sqlx::migrate!("./migrations");
|
||||
migrations.run(&pool).await.expect("Migrations failed");
|
||||
|
||||
println!("Migrations complete");
|
||||
|
||||
// Gets new Redis pool
|
||||
let redis_pool = RedisPool::new(Some(temp_database_name.clone()));
|
||||
|
||||
|
||||
@@ -13,6 +13,16 @@ use super::{
|
||||
environment::TestEnvironment,
|
||||
};
|
||||
|
||||
pub const DUMMY_CATEGORIES: &'static [&str] = &[
|
||||
"combat",
|
||||
"decoration",
|
||||
"economy",
|
||||
"food",
|
||||
"magic",
|
||||
"mobs",
|
||||
"optimization",
|
||||
];
|
||||
|
||||
pub struct DummyData {
|
||||
pub alpha_team_id: String,
|
||||
pub beta_team_id: String,
|
||||
|
||||
@@ -3,6 +3,19 @@
|
||||
use super::{database::TemporaryDatabase, dummy_data};
|
||||
use crate::common::setup;
|
||||
use actix_web::{dev::ServiceResponse, test, App};
|
||||
use futures::Future;
|
||||
|
||||
pub async fn with_test_environment<Fut>(f: impl FnOnce(TestEnvironment) -> Fut)
|
||||
where
|
||||
Fut: Future<Output = ()>,
|
||||
{
|
||||
let test_env = TestEnvironment::build_with_dummy().await;
|
||||
let db = test_env.db.clone();
|
||||
|
||||
f(test_env).await;
|
||||
|
||||
db.cleanup().await;
|
||||
}
|
||||
|
||||
// A complete test environment, with a test actix app and a database.
|
||||
// Must be called in an #[actix_rt::test] context. It also simulates a
|
||||
|
||||
Reference in New Issue
Block a user