mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 14:45:10 +00:00
try to run migrations on db connection in tests
This commit is contained in:
parent
6075f7d2f1
commit
cbe5cf8ca0
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -935,16 +935,6 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ctor"
|
|
||||||
version = "0.1.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7fbaabec2c953050352311293be5c6aba8e141ba19d6811862b232d6fd020484"
|
|
||||||
dependencies = [
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "darling"
|
name = "darling"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
|
@ -1809,6 +1799,7 @@ dependencies = [
|
||||||
"bcrypt",
|
"bcrypt",
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel",
|
"diesel",
|
||||||
|
"diesel_migrations",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"log",
|
"log",
|
||||||
|
@ -1848,7 +1839,6 @@ dependencies = [
|
||||||
"awc",
|
"awc",
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"chrono",
|
"chrono",
|
||||||
"ctor",
|
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel_migrations",
|
"diesel_migrations",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
|
|
@ -49,7 +49,6 @@ reqwest = { version = "0.10", features = ["json"] }
|
||||||
activitystreams = "0.7.0-alpha.4"
|
activitystreams = "0.7.0-alpha.4"
|
||||||
actix-rt = { version = "1.1", default-features = false }
|
actix-rt = { version = "1.1", default-features = false }
|
||||||
serde_json = { version = "1.0", features = ["preserve_order"]}
|
serde_json = { version = "1.0", features = ["preserve_order"]}
|
||||||
ctor = "0.1.16"
|
|
||||||
|
|
||||||
[dev-dependencies.cargo-husky]
|
[dev-dependencies.cargo-husky]
|
||||||
version = "1"
|
version = "1"
|
||||||
|
|
|
@ -10,6 +10,7 @@ path = "src/lib.rs"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_utils = { path = "../lemmy_utils" }
|
lemmy_utils = { path = "../lemmy_utils" }
|
||||||
diesel = { version = "1.4", features = ["postgres","chrono","r2d2","64-column-tables","serde_json"] }
|
diesel = { version = "1.4", features = ["postgres","chrono","r2d2","64-column-tables","serde_json"] }
|
||||||
|
diesel_migrations = "1.4"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = { version = "1.0", features = ["preserve_order"]}
|
serde_json = { version = "1.0", features = ["preserve_order"]}
|
||||||
|
|
|
@ -4,6 +4,8 @@ extern crate diesel;
|
||||||
extern crate strum_macros;
|
extern crate strum_macros;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate diesel_migrations;
|
||||||
|
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
|
@ -214,11 +216,13 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod tests {
|
mod tests {
|
||||||
use super::fuzzy_search;
|
use super::fuzzy_search;
|
||||||
use crate::{get_database_url_from_env, is_email_regex};
|
use crate::{get_database_url_from_env, is_email_regex};
|
||||||
use diesel::{Connection, PgConnection};
|
use diesel::{Connection, PgConnection};
|
||||||
|
|
||||||
|
embed_migrations!();
|
||||||
|
|
||||||
pub fn establish_unpooled_connection() -> PgConnection {
|
pub fn establish_unpooled_connection() -> PgConnection {
|
||||||
let db_url = match get_database_url_from_env() {
|
let db_url = match get_database_url_from_env() {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
|
@ -227,7 +231,9 @@ pub mod tests {
|
||||||
e
|
e
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url))
|
let conn = PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
|
||||||
|
embedded_migrations::run(&conn).unwrap();
|
||||||
|
conn
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -92,12 +92,3 @@ async fn main() -> Result<(), LemmyError> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[ctor::ctor]
|
|
||||||
fn init() {
|
|
||||||
use lemmy_db::tests::establish_unpooled_connection;
|
|
||||||
let conn = establish_unpooled_connection();
|
|
||||||
embedded_migrations::run(&conn).unwrap();
|
|
||||||
run_advanced_migrations(&conn).unwrap();
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue