diff --git a/src/index.rs b/src/index.rs index e8d358e..db31571 100644 --- a/src/index.rs +++ b/src/index.rs @@ -99,7 +99,6 @@ impl Index { ) }; - println!("remember {:?}", item); self.items_by_file_id.insert(item.id.clone(), item.clone()); self.newest_items_by_source_path .insert(original_source_path.to_string_lossy().to_string(), item.clone()); diff --git a/src/test/assertions.rs b/src/test/assertions.rs index 4e1835e..91a85df 100644 --- a/src/test/assertions.rs +++ b/src/test/assertions.rs @@ -7,6 +7,7 @@ use walkdir::WalkDir; use crate::error::BakareError; use crate::repository::{ItemId, Repository}; +use crate::repository_item::RepositoryItem; use crate::source::TempSource; use crate::{backup, restore}; @@ -62,15 +63,14 @@ pub fn assert_restored_from_version_has_contents( assert_target_file_contents(&restored_file_path, old_contents) } -pub fn item_id(repository_path: &Path, source_file_full_path: &Path) -> Result { - let id = { +pub fn newest_item(repository_path: &Path, source_file_full_path: &Path) -> Result { + let item = { let reading_repository = Repository::open(repository_path)?; let item = reading_repository.newest_item_by_source_path(&source_file_full_path)?; assert!(item.is_some()); - let item = item.unwrap(); - item.id().clone() + item.unwrap() }; - Ok(id) + Ok(item) } pub fn restore_all_from_reloaded_repository(repository_path: &Path, restore_target: &Path) -> Result<(), BakareError> { diff --git a/tests/system_tests.rs b/tests/system_tests.rs index 0d2e7e5..205eef7 100644 --- a/tests/system_tests.rs +++ b/tests/system_tests.rs @@ -47,12 +47,37 @@ fn restore_older_version_of_file() -> Result<(), BakareError> { backup_file_with_contents(&source, &repository_path, source_file_relative_path, old_contents)?; - let old_version = item_id(&repository_path, &source_file_full_path)?; + let old_item = newest_item(&repository_path, &source_file_full_path)?; + let old_id = old_item.id(); let new_contents = "totally new contents"; backup_file_with_contents(&source, &repository_path, source_file_relative_path, new_contents)?; - assert_restored_from_version_has_contents(&repository_path, &source_file_full_path, old_contents, &old_version) + assert_restored_from_version_has_contents(&repository_path, &source_file_full_path, old_contents, &old_id) +} + +#[test] +fn newer_version_should_be_greater_than_earlier_version() -> Result<(), BakareError> { + let source = TempSource::new()?; + let repository_path = tempdir()?.into_path(); + Repository::init(repository_path.as_path())?; + + let source_file_relative_path = "some path"; + let source_file_full_path = source.file_path(source_file_relative_path); + + backup_file_with_contents(&source, &repository_path, source_file_relative_path, "old")?; + + let old_item = newest_item(&repository_path, &source_file_full_path)?; + let old_version = old_item.version(); + + backup_file_with_contents(&source, &repository_path, source_file_relative_path, "new")?; + + let new_item = newest_item(&repository_path, &source_file_full_path)?; + let new_version = new_item.version(); + + assert!(new_version > old_version); + + Ok(()) } #[test] @@ -84,8 +109,8 @@ fn forbid_backup_of_paths_within_repository() -> Result<(), BakareError> { Ok(()) } +// TODO: test concurrent writes // TODO: deduplicate data // TODO: test that index is stored separately from data // TODO: index corruption // TODO: newer version should be greater than older version -// TODO: split version into file id and version