add wrapping modules in integration tests
This commit is contained in:
parent
5728645add
commit
4266f48b03
3 changed files with 218 additions and 211 deletions
|
@ -1,16 +1,17 @@
|
|||
use std::fs;
|
||||
use std::path::Path;
|
||||
#[cfg(test)]
|
||||
mod must {
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::Result;
|
||||
use bakare::repository::Repository;
|
||||
use bakare::test::{assertions::*, source::TestSource};
|
||||
use bakare::{backup, restore};
|
||||
use nix::sys::wait::{waitpid, WaitStatus};
|
||||
use nix::unistd::{fork, ForkResult};
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[test]
|
||||
fn handle_concurrent_backups() -> Result<()> {
|
||||
use anyhow::Result;
|
||||
use bakare::repository::Repository;
|
||||
use bakare::test::{assertions::*, source::TestSource};
|
||||
use bakare::{backup, restore};
|
||||
use nix::sys::wait::{waitpid, WaitStatus};
|
||||
use nix::unistd::{fork, ForkResult};
|
||||
use tempfile::tempdir;
|
||||
#[test]
|
||||
fn handle_concurrent_backups() -> Result<()> {
|
||||
setup_logger();
|
||||
let repository_path = &tempdir().unwrap().into_path();
|
||||
Repository::init(repository_path)?;
|
||||
|
@ -34,16 +35,16 @@ fn handle_concurrent_backups() -> Result<()> {
|
|||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn backup_in_parallel<T>(
|
||||
fn backup_in_parallel<T>(
|
||||
repository_path: T,
|
||||
parallel_backups_number: usize,
|
||||
files_per_backup_number: usize,
|
||||
) -> Result<Vec<usize>>
|
||||
where
|
||||
) -> Result<Vec<usize>>
|
||||
where
|
||||
T: AsRef<Path> + Sync,
|
||||
{
|
||||
{
|
||||
let task_numbers = (0..parallel_backups_number).collect::<Vec<_>>();
|
||||
let mut child_pids = vec![];
|
||||
for task_number in &task_numbers {
|
||||
|
@ -70,12 +71,12 @@ where
|
|||
}
|
||||
}
|
||||
Ok(task_numbers)
|
||||
}
|
||||
}
|
||||
|
||||
fn backup_process<T>(task_number: usize, repository_path: T, files_per_backup_number: usize) -> Result<()>
|
||||
where
|
||||
fn backup_process<T>(task_number: usize, repository_path: T, files_per_backup_number: usize) -> Result<()>
|
||||
where
|
||||
T: AsRef<Path> + Sync,
|
||||
{
|
||||
{
|
||||
let mut repository = Repository::open(repository_path.as_ref())?;
|
||||
let source = TestSource::new().unwrap();
|
||||
let mut backup_engine = backup::Engine::new(source.path(), &mut repository)?;
|
||||
|
@ -85,20 +86,21 @@ where
|
|||
}
|
||||
backup_engine.backup()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn restore_all<T: AsRef<Path>>(repository_path: T) -> Result<Vec<Box<Path>>> {
|
||||
fn restore_all<T: AsRef<Path>>(repository_path: T) -> Result<Vec<Box<Path>>> {
|
||||
let restore_target = tempdir().unwrap().into_path();
|
||||
let mut restore_repository = Repository::open(repository_path.as_ref())?;
|
||||
let mut restore_engine = restore::Engine::new(&mut restore_repository, restore_target.as_ref())?;
|
||||
restore_engine.restore_all()?;
|
||||
get_sorted_files_recursively(&restore_target)
|
||||
}
|
||||
}
|
||||
|
||||
fn setup_logger() {
|
||||
fn setup_logger() {
|
||||
femme::with_level(log::LevelFilter::Info);
|
||||
}
|
||||
}
|
||||
|
||||
fn file_id(i: usize, j: usize) -> String {
|
||||
fn file_id(i: usize, j: usize) -> String {
|
||||
format!("{}-{}", i, j)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
use tempfile::tempdir;
|
||||
#[cfg(test)]
|
||||
mod must {
|
||||
use tempfile::tempdir;
|
||||
|
||||
use bakare::repository::Repository;
|
||||
use bakare::test::{assertions::*, source::TestSource};
|
||||
use bakare::repository::Repository;
|
||||
use bakare::test::{assertions::*, source::TestSource};
|
||||
|
||||
use proptest::prelude::*;
|
||||
|
||||
proptest! {
|
||||
use proptest::prelude::*;
|
||||
proptest! {
|
||||
#[test]
|
||||
fn store_duplicated_files_just_once(contents in any::<[u8;3]>()) {
|
||||
let source = TestSource::new().unwrap();
|
||||
|
@ -24,4 +25,5 @@ proptest! {
|
|||
assert_restored_file_contents(repository_path, &source.file_path("1"), &contents).unwrap();
|
||||
assert_restored_file_contents(repository_path, &source.file_path("2"), &contents).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
use tempfile::tempdir;
|
||||
#[cfg(test)]
|
||||
mod must {
|
||||
use tempfile::tempdir;
|
||||
|
||||
use anyhow::Result;
|
||||
use bakare::backup;
|
||||
use bakare::repository::Repository;
|
||||
use bakare::test::{assertions::*, source::TestSource};
|
||||
use anyhow::Result;
|
||||
use bakare::backup;
|
||||
use bakare::repository::Repository;
|
||||
use bakare::test::{assertions::*, source::TestSource};
|
||||
|
||||
#[test]
|
||||
fn restore_multiple_files() -> Result<()> {
|
||||
#[test]
|
||||
fn restore_multiple_files() -> Result<()> {
|
||||
let source = TestSource::new().unwrap();
|
||||
|
||||
source.write_text_to_file("first", "some contents").unwrap();
|
||||
|
@ -14,10 +16,10 @@ fn restore_multiple_files() -> Result<()> {
|
|||
source.write_text_to_file("third", "some other contents").unwrap();
|
||||
|
||||
assert_same_after_restore(source.path())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_files_after_reopening_repository() -> Result<()> {
|
||||
#[test]
|
||||
fn restore_files_after_reopening_repository() -> Result<()> {
|
||||
let source = TestSource::new().unwrap();
|
||||
let repository_path = &tempdir().unwrap().into_path();
|
||||
let restore_target = tempdir().unwrap().into_path();
|
||||
|
@ -32,10 +34,10 @@ fn restore_files_after_reopening_repository() -> Result<()> {
|
|||
|
||||
let source_file_full_path = &source.file_path(source_file_relative_path);
|
||||
assert_restored_file_contents(repository_path, source_file_full_path, original_contents.as_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_older_version_of_file() -> Result<()> {
|
||||
#[test]
|
||||
fn restore_older_version_of_file() -> Result<()> {
|
||||
let source = TestSource::new().unwrap();
|
||||
let repository_path = tempdir().unwrap().into_path();
|
||||
Repository::init(repository_path.as_path())?;
|
||||
|
@ -53,10 +55,10 @@ fn restore_older_version_of_file() -> Result<()> {
|
|||
backup_file_with_text_contents(&source, &repository_path, source_file_relative_path, new_contents)?;
|
||||
|
||||
assert_restored_from_version_has_contents(&repository_path, &source_file_full_path, old_contents.as_bytes(), &old_id)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn newer_version_should_be_greater_than_earlier_version() -> Result<()> {
|
||||
#[test]
|
||||
fn newer_version_should_be_greater_than_earlier_version() -> Result<()> {
|
||||
let source = TestSource::new().unwrap();
|
||||
let repository_path = tempdir().unwrap().into_path();
|
||||
Repository::init(repository_path.as_path())?;
|
||||
|
@ -77,10 +79,10 @@ fn newer_version_should_be_greater_than_earlier_version() -> Result<()> {
|
|||
assert!(new_version > old_version);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_latest_version_by_default() -> Result<()> {
|
||||
#[test]
|
||||
fn restore_latest_version_by_default() -> Result<()> {
|
||||
let source = TestSource::new().unwrap();
|
||||
let repository_path = &tempdir().unwrap().into_path();
|
||||
Repository::init(repository_path)?;
|
||||
|
@ -92,17 +94,18 @@ fn restore_latest_version_by_default() -> Result<()> {
|
|||
|
||||
let source_file_full_path = &source.file_path(source_file_relative_path);
|
||||
assert_restored_file_contents(repository_path, source_file_full_path, b"newest contents")
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forbid_backup_of_paths_within_repository() -> Result<()> {
|
||||
#[test]
|
||||
fn forbid_backup_of_paths_within_repository() -> Result<()> {
|
||||
let repository_path = &tempdir().unwrap().into_path();
|
||||
Repository::init(repository_path)?;
|
||||
let mut repository = Repository::open(repository_path)?;
|
||||
let error = backup::Engine::new(repository_path, &mut repository);
|
||||
assert!(error.is_err());
|
||||
Ok(())
|
||||
}
|
||||
// TODO: index corruption
|
||||
// TODO: encryption
|
||||
// TODO: resume from sleep while backup in progress
|
||||
}
|
||||
// TODO: index corruption
|
||||
// TODO: encryption
|
||||
// TODO: resume from sleep while backup in progress
|
||||
|
|
Loading…
Reference in a new issue