Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply the same tests to all storage backends #453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 3 additions & 66 deletions taskchampion/src/storage/inmemory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,73 +202,10 @@ impl Storage for InMemoryStorage {
#[cfg(test)]
mod test {
use super::*;
use pretty_assertions::assert_eq;

// (note: this module is heavily used in tests so most of its functionality is well-tested
// elsewhere and not tested here)

#[test]
fn get_working_set_empty() -> Result<()> {
let mut storage = InMemoryStorage::new();

{
let mut txn = storage.txn()?;
let ws = txn.get_working_set()?;
assert_eq!(ws, vec![None]);
}

Ok(())
}

#[test]
fn add_to_working_set() -> Result<()> {
let mut storage = InMemoryStorage::new();
let uuid1 = Uuid::new_v4();
let uuid2 = Uuid::new_v4();

{
let mut txn = storage.txn()?;
txn.add_to_working_set(uuid1)?;
txn.add_to_working_set(uuid2)?;
txn.commit()?;
}

{
let mut txn = storage.txn()?;
let ws = txn.get_working_set()?;
assert_eq!(ws, vec![None, Some(uuid1), Some(uuid2)]);
}

Ok(())
fn storage() -> InMemoryStorage {
InMemoryStorage::new()
}

#[test]
fn clear_working_set() -> Result<()> {
let mut storage = InMemoryStorage::new();
let uuid1 = Uuid::new_v4();
let uuid2 = Uuid::new_v4();

{
let mut txn = storage.txn()?;
txn.add_to_working_set(uuid1)?;
txn.add_to_working_set(uuid2)?;
txn.commit()?;
}

{
let mut txn = storage.txn()?;
txn.clear_working_set()?;
txn.add_to_working_set(uuid2)?;
txn.add_to_working_set(uuid1)?;
txn.commit()?;
}

{
let mut txn = storage.txn()?;
let ws = txn.get_working_set()?;
assert_eq!(ws, vec![None, Some(uuid2), Some(uuid1)]);
}

Ok(())
}
crate::storage::test::storage_tests!(storage());
}
3 changes: 3 additions & 0 deletions taskchampion/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use crate::operation::Operation;
use std::collections::HashMap;
use uuid::Uuid;

#[cfg(test)]
mod test;

mod config;
mod inmemory;
pub(crate) mod sqlite;
Expand Down
Loading
Loading