Add a test for State
This commit is contained in:
parent
7b485f87b9
commit
2665fb3b8a
5 changed files with 31 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -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)",
|
||||
|
|
|
@ -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"
|
||||
|
|
11
src/db.rs
11
src/db.rs
|
@ -30,3 +30,14 @@ pub fn create_pool<S: Into<String>>(connection_string: S) -> Result<Pool<Connect
|
|||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
14
src/state.rs
14
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue