bakare/tests/system_tests.rs

81 lines
2.7 KiB
Rust
Raw Normal View History

2019-09-07 14:42:30 +01:00
use tempfile::tempdir;
2018-12-22 11:31:27 +00:00
2019-09-07 15:08:47 +01:00
use bakare::backup;
2019-01-12 14:42:53 +00:00
use bakare::error::BakareError;
use bakare::repository::Repository;
2019-09-07 14:19:03 +01:00
use bakare::source::TempSource;
2019-09-07 14:42:30 +01:00
use bakare::test::assertions::*;
2018-10-04 15:29:19 +01:00
#[test]
fn restore_multiple_files() -> Result<(), BakareError> {
2019-01-26 19:27:23 +00:00
let source = TempSource::new()?;
2018-10-04 15:29:19 +01:00
2018-10-04 15:30:18 +01:00
source.write_text_to_file("first", "some contents")?;
source.write_text_to_file("second", "some contents")?;
source.write_text_to_file("third", "some other contents")?;
2018-10-04 15:29:19 +01:00
2019-01-12 14:42:53 +00:00
assert_same_after_restore(source.path())
2018-10-04 15:29:19 +01:00
}
#[test]
fn restore_files_after_reopening_repository() -> Result<(), BakareError> {
let source = TempSource::new()?;
let repository_path = tempdir()?.into_path();
let restore_target = tempdir()?.into_path();
Repository::init(repository_path.as_path())?;
2019-09-07 10:29:27 +01:00
let source_file_relative_path = "some file path";
let original_contents = "some old contents";
2019-09-07 14:42:30 +01:00
backup_file_with_contents(&source, &repository_path, source_file_relative_path, original_contents)?;
2019-09-07 14:42:30 +01:00
restore_all_from_reloaded_repository(&repository_path, &restore_target)?;
2019-09-07 14:42:30 +01:00
let contents = read_restored_file_contents(source, &restore_target, source_file_relative_path)?;
assert_eq!(contents, original_contents);
Ok(())
}
2018-10-04 15:29:19 +01:00
#[test]
2019-01-12 14:39:20 +00:00
fn restore_older_version_of_file() -> Result<(), BakareError> {
2019-01-26 19:27:23 +00:00
let source = TempSource::new()?;
2019-01-12 14:39:20 +00:00
let repository_path = tempdir()?.into_path();
Repository::init(repository_path.as_path())?;
2019-09-01 11:05:22 +01:00
2019-09-07 14:19:03 +01:00
let source_file_relative_path = "some path";
let source_file_full_path = source.file_path(source_file_relative_path);
2018-10-04 15:29:19 +01:00
let old_contents = "some old contents";
2019-09-07 14:42:30 +01:00
backup_file_with_contents(&source, &repository_path, source_file_relative_path, old_contents)?;
let old_version = item_version(&repository_path, &source_file_full_path)?;
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)
2018-10-04 15:29:19 +01:00
}
2019-09-07 15:08:47 +01:00
#[test]
fn forbid_backup_of_paths_within_repository() -> Result<(), BakareError> {
let repository_path = &tempdir()?.into_path();
Repository::init(repository_path)?;
let mut repository = Repository::open(repository_path)?;
if let Err(e) = backup::Engine::new(repository_path, &mut repository) {
let correct_error = match e {
BakareError::SourceSameAsRepository => true,
_ => false,
};
assert!(correct_error);
} else {
panic!("Expected error");
}
Ok(())
}
2019-01-12 14:42:53 +00:00
// TODO: restore latest version by default
// TODO: deduplicate data
2019-09-07 11:37:31 +01:00
// TODO: test that index is stored separately from data
// TODO: index corruption