2020-09-29 00:33:43 +00:00
|
|
|
mod errors;
|
|
|
|
mod store;
|
|
|
|
mod structs;
|
|
|
|
|
|
|
|
pub use crate::errors::NoteStoreError;
|
2020-09-29 15:08:30 +00:00
|
|
|
pub use crate::store::NoteStore;
|
2020-09-29 00:33:43 +00:00
|
|
|
|
2020-09-27 12:35:37 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-09-29 15:08:30 +00:00
|
|
|
use super::*;
|
|
|
|
use tokio;
|
2020-09-29 00:33:43 +00:00
|
|
|
|
2020-09-29 15:08:30 +00:00
|
|
|
async fn fresh_inmemory_database() -> NoteStore {
|
|
|
|
let storagepool = NoteStore::new("sqlite://:memory:").await;
|
|
|
|
assert!(storagepool.is_ok());
|
|
|
|
let storagepool = storagepool.unwrap();
|
|
|
|
assert!(storagepool.reset_database().await.is_ok());
|
|
|
|
storagepool
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test(threaded_scheduler)]
|
2020-09-29 14:44:43 +00:00
|
|
|
async fn fetching_unfound_page_works() {
|
2020-09-29 15:08:30 +00:00
|
|
|
let storagepool = fresh_inmemory_database().await;
|
|
|
|
let unfoundpage = storagepool.fetch_page("nonexistent-page").await;
|
|
|
|
assert!(unfoundpage.is_err());
|
2020-09-27 12:35:37 +00:00
|
|
|
}
|
2020-09-29 14:44:43 +00:00
|
|
|
|
2020-09-29 15:08:30 +00:00
|
|
|
#[tokio::test(threaded_scheduler)]
|
2020-09-29 14:44:43 +00:00
|
|
|
async fn fetching_unfound_note_works() {
|
2020-09-29 15:08:30 +00:00
|
|
|
let storagepool = fresh_inmemory_database().await;
|
|
|
|
let unfoundnote = storagepool.fetch_note("nonexistent-note").await;
|
|
|
|
assert!(unfoundnote.is_err());
|
2020-09-29 14:44:43 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 15:08:30 +00:00
|
|
|
#[tokio::test(threaded_scheduler)]
|
|
|
|
async fn cloning_storagepool_is_ok() {
|
|
|
|
let storagepool = fresh_inmemory_database().await;
|
|
|
|
let storagepool2 = storagepool.clone();
|
|
|
|
let unfoundnote = storagepool2.fetch_note("nonexistent-note").await;
|
|
|
|
assert!(unfoundnote.is_err());
|
|
|
|
let unfoundnote = storagepool.fetch_note("nonexistent-note").await;
|
|
|
|
assert!(unfoundnote.is_err());
|
|
|
|
}
|
2020-09-27 12:35:37 +00:00
|
|
|
}
|