Fix empty-dir problem with server also, and add tests
This commit is contained in:
@@ -61,6 +61,7 @@ impl SqliteStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn new<P: AsRef<Path>>(directory: P) -> anyhow::Result<SqliteStorage> {
|
pub fn new<P: AsRef<Path>>(directory: P) -> anyhow::Result<SqliteStorage> {
|
||||||
|
std::fs::create_dir_all(&directory)?;
|
||||||
let db_file = directory.as_ref().join("taskchampion-sync-server.sqlite3");
|
let db_file = directory.as_ref().join("taskchampion-sync-server.sqlite3");
|
||||||
|
|
||||||
let o = SqliteStorage { db_file };
|
let o = SqliteStorage { db_file };
|
||||||
@@ -208,6 +209,17 @@ mod test {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_emtpy_dir() -> anyhow::Result<()> {
|
||||||
|
let tmp_dir = TempDir::new()?;
|
||||||
|
let non_existant = tmp_dir.path().join("subdir");
|
||||||
|
let storage = SqliteStorage::new(&non_existant)?;
|
||||||
|
let mut txn = storage.txn()?;
|
||||||
|
let maybe_client = txn.get_client(Uuid::new_v4())?;
|
||||||
|
assert!(maybe_client.is_none());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_client_empty() -> anyhow::Result<()> {
|
fn test_get_client_empty() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new()?;
|
let tmp_dir = TempDir::new()?;
|
||||||
|
|||||||
@@ -351,6 +351,25 @@ mod test {
|
|||||||
use crate::storage::taskmap_with;
|
use crate::storage::taskmap_with;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_empty_dir() -> anyhow::Result<()> {
|
||||||
|
let tmp_dir = TempDir::new()?;
|
||||||
|
let non_existant = tmp_dir.path().join("subdir");
|
||||||
|
let mut storage = SqliteStorage::new(&non_existant)?;
|
||||||
|
let uuid = Uuid::new_v4();
|
||||||
|
{
|
||||||
|
let mut txn = storage.txn()?;
|
||||||
|
assert!(txn.create_task(uuid)?);
|
||||||
|
txn.commit()?;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
let mut txn = storage.txn()?;
|
||||||
|
let task = txn.get_task(uuid)?;
|
||||||
|
assert_eq!(task, Some(taskmap_with(vec![])));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn drop_transaction() -> anyhow::Result<()> {
|
fn drop_transaction() -> anyhow::Result<()> {
|
||||||
let tmp_dir = TempDir::new()?;
|
let tmp_dir = TempDir::new()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user