Add a test for State

This commit is contained in:
Magnus Hoff 2017-11-15 16:27:28 +01:00
parent 7b485f87b9
commit 2665fb3b8a
5 changed files with 31 additions and 0 deletions

1
Cargo.lock generated
View file

@ -595,6 +595,7 @@ dependencies = [
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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)", "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)", "pulldown-cmark 0.0.11 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -8,6 +8,9 @@ license = "GPL-3.0"
[profile.release] [profile.release]
panic = "abort" panic = "abort"
[dev-dependencies]
matches = "0.1"
[dependencies] [dependencies]
bart = "0.1.4" bart = "0.1.4"
bart_derive = "0.1.4" bart_derive = "0.1.4"

View file

@ -30,3 +30,14 @@ pub fn create_pool<S: Into<String>>(connection_string: S) -> Result<Pool<Connect
Ok(pool) Ok(pool)
} }
#[cfg(test)]
pub fn test_connection() -> 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
}

View file

@ -1,5 +1,7 @@
#![recursion_limit="128"] // for diesel's infer_schema! #![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 bart_derive;
#[macro_use] extern crate codegen; #[macro_use] extern crate codegen;
#[macro_use] extern crate diesel_codegen; #[macro_use] extern crate diesel_codegen;

View file

@ -384,3 +384,17 @@ impl State {
self.execute(move |state| state.search_query(query_string, limit, offset, snippet_size)) 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));
}
}