]> Untitled Git - lemmy.git/commitdiff
try to init db from lemmy in tests
authorFelix Ableitner <me@nutomic.com>
Fri, 11 Dec 2020 13:49:10 +0000 (14:49 +0100)
committerFelix Ableitner <me@nutomic.com>
Fri, 11 Dec 2020 13:49:10 +0000 (14:49 +0100)
.drone.yml
Cargo.lock
Cargo.toml
lemmy_db/src/lib.rs
src/main.rs

index c9d0a100db09237e784d7a93adf4e1bfa26dbdca..c6977ed9cf091cf34e2acaab675f4fba665df68a 100644 (file)
@@ -34,9 +34,6 @@ steps:
     commands:
       - sudo apt-get update
       - sudo apt-get -y install --no-install-recommends espeak postgresql-client
-      - cargo install diesel_cli --no-default-features --features postgres --target-dir target/
-      - ls -la target/
-      - ./target/diesel migration run
       - cargo test --workspace --no-fail-fast
 
   - name: cargo build
index cf741d68948e1e557d398e027646dd50be90e570..ef39f5fd53b4b94ba71fe17855763036269a4714 100644 (file)
@@ -935,6 +935,16 @@ dependencies = [
  "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]]
 name = "darling"
 version = "0.10.2"
@@ -1838,6 +1848,7 @@ dependencies = [
  "awc",
  "cargo-husky",
  "chrono",
+ "ctor",
  "diesel",
  "diesel_migrations",
  "env_logger",
index 99d755cc0b2a2b3532778acb9531c3d98983b6f1..ad5a6cd52f871787cdd65ddb3d0f9620a4aec988 100644 (file)
@@ -49,6 +49,7 @@ reqwest = { version = "0.10", features = ["json"] }
 activitystreams = "0.7.0-alpha.4"
 actix-rt = { version = "1.1", default-features = false }
 serde_json = { version = "1.0", features = ["preserve_order"]}
+ctor = "0.1.16"
 
 [dev-dependencies.cargo-husky]
 version = "1"
index bad646d14be2b3d73dd0080da80e10b3f341932a..b90c9416ff9ceb6d658043c8888c448b27502dde 100644 (file)
@@ -214,7 +214,7 @@ lazy_static! {
 }
 
 #[cfg(test)]
-mod tests {
+pub mod tests {
   use super::fuzzy_search;
   use crate::{get_database_url_from_env, is_email_regex};
   use diesel::{Connection, PgConnection};
index c55c3655d586e565718ef200ab8fa8b40369f365..31c5f97090d8905965b839e4f47fe2c37e64d140 100644 (file)
@@ -92,3 +92,12 @@ async fn main() -> Result<(), LemmyError> {
 
   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();
+}
\ No newline at end of file