diff --git a/Cargo.lock b/Cargo.lock index 297c49d..be7f670 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -595,6 +595,7 @@ dependencies = [ "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "libsqlite3-sys 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "maplit 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.0.11 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index e9a51df..bd8f95e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,9 @@ license = "GPL-3.0" [profile.release] panic = "abort" +[dev-dependencies] +matches = "0.1" + [dependencies] bart = "0.1.4" bart_derive = "0.1.4" diff --git a/src/db.rs b/src/db.rs index 33f4909..f9bb4c4 100644 --- a/src/db.rs +++ b/src/db.rs @@ -30,3 +30,14 @@ pub fn create_pool>(connection_string: S) -> Result SqliteConnection { + let mut conn = SqliteConnection::establish(":memory:") + .expect("SQLite should be able to create an in-memory database"); + + SqliteInitializer.on_acquire(&mut conn).unwrap(); + embedded_migrations::run(&conn).unwrap(); + + conn +} diff --git a/src/lib.rs b/src/lib.rs index bc7d884..c973f2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ #![recursion_limit="128"] // for diesel's infer_schema! +#[cfg(test)] #[macro_use] extern crate matches; + #[macro_use] extern crate bart_derive; #[macro_use] extern crate codegen; #[macro_use] extern crate diesel_codegen; diff --git a/src/state.rs b/src/state.rs index b6bf468..216431e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -384,3 +384,17 @@ impl State { self.execute(move |state| state.search_query(query_string, limit, offset, snippet_size)) } } + +#[cfg(test)] +mod test { + use super::*; + use db; + + #[test] + fn get_article_slug() { + let db = db::test_connection(); + let state = SyncState::new(&db); + + assert_matches!(state.get_article_slug(0), Ok(None)); + } +}