Skip to content

Commit

Permalink
Apply the same tests to all storage backends (GothenburgBitFactory#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche authored Sep 8, 2024
1 parent d7a7d96 commit c7c2cde
Show file tree
Hide file tree
Showing 4 changed files with 579 additions and 581 deletions.
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

0 comments on commit c7c2cde

Please sign in to comment.