better name for the test source
This commit is contained in:
parent
9514d1b341
commit
f9613cb266
5 changed files with 35 additions and 16 deletions
|
@ -172,7 +172,7 @@ impl<'a> Repository<'a> {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod must {
|
mod must {
|
||||||
use super::Repository;
|
use super::Repository;
|
||||||
use crate::test::source::TempSource;
|
use crate::test::source::TestSource;
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ mod must {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn have_size_equal_to_sum_of_sizes_of_backed_up_files(file_size1 in 0u64..128, file_size2 in 0u64..128) {
|
fn have_size_equal_to_sum_of_sizes_of_backed_up_files(file_size1 in 0u64..128, file_size2 in 0u64..128) {
|
||||||
let source = TempSource::new().unwrap();
|
let source = TestSource::new().unwrap();
|
||||||
let repository_path = tempdir().unwrap().into_path();
|
let repository_path = tempdir().unwrap().into_path();
|
||||||
Repository::init(&repository_path).unwrap();
|
Repository::init(&repository_path).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::path::Path;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use super::source::TempSource;
|
use super::source::TestSource;
|
||||||
use crate::repository::{item::RepositoryItem, ItemId, Repository};
|
use crate::repository::{item::RepositoryItem, ItemId, Repository};
|
||||||
use crate::{backup, restore};
|
use crate::{backup, restore};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
@ -89,7 +89,7 @@ pub fn restore_all_from_reloaded_repository(repository_path: &Path, restore_targ
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn backup_file_with_text_contents(
|
pub fn backup_file_with_text_contents(
|
||||||
source: &TempSource,
|
source: &TestSource,
|
||||||
repository_path: &Path,
|
repository_path: &Path,
|
||||||
source_file_relative_path: &str,
|
source_file_relative_path: &str,
|
||||||
contents: &str,
|
contents: &str,
|
||||||
|
@ -100,7 +100,7 @@ pub fn backup_file_with_text_contents(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn backup_file_with_byte_contents(
|
pub fn backup_file_with_byte_contents(
|
||||||
source: &TempSource,
|
source: &TestSource,
|
||||||
repository_path: &Path,
|
repository_path: &Path,
|
||||||
source_file_relative_path: &str,
|
source_file_relative_path: &str,
|
||||||
contents: &[u8],
|
contents: &[u8],
|
||||||
|
|
|
@ -7,11 +7,11 @@ use std::path::PathBuf;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
pub struct TempSource {
|
pub struct TestSource {
|
||||||
directory: TempDir,
|
directory: TempDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TempSource {
|
impl TestSource {
|
||||||
pub fn new() -> Result<Self, Error> {
|
pub fn new() -> Result<Self, Error> {
|
||||||
Ok(Self { directory: tempdir()? })
|
Ok(Self { directory: tempdir()? })
|
||||||
}
|
}
|
||||||
|
@ -39,3 +39,22 @@ impl TempSource {
|
||||||
self.directory.path().join(filename)
|
self.directory.path().join(filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod must {
|
||||||
|
use super::TestSource;
|
||||||
|
use anyhow::Result;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn leave_no_trace() -> Result<()> {
|
||||||
|
let path;
|
||||||
|
{
|
||||||
|
let source = TestSource::new()?;
|
||||||
|
source.write_random_bytes_to_file("somefile", 1)?;
|
||||||
|
path = source.path().to_path_buf();
|
||||||
|
}
|
||||||
|
|
||||||
|
assert!(!path.exists());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::path::Path;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bakare::repository::Repository;
|
use bakare::repository::Repository;
|
||||||
use bakare::test::{assertions::*, source::TempSource};
|
use bakare::test::{assertions::*, source::TestSource};
|
||||||
use bakare::{backup, restore};
|
use bakare::{backup, restore};
|
||||||
use nix::sys::wait::{waitpid, WaitStatus};
|
use nix::sys::wait::{waitpid, WaitStatus};
|
||||||
use nix::unistd::{fork, ForkResult};
|
use nix::unistd::{fork, ForkResult};
|
||||||
|
@ -77,7 +77,7 @@ where
|
||||||
T: AsRef<Path> + Sync,
|
T: AsRef<Path> + Sync,
|
||||||
{
|
{
|
||||||
let mut repository = Repository::open(repository_path.as_ref())?;
|
let mut repository = Repository::open(repository_path.as_ref())?;
|
||||||
let source = TempSource::new().unwrap();
|
let source = TestSource::new().unwrap();
|
||||||
let mut backup_engine = backup::Engine::new(source.path(), &mut repository)?;
|
let mut backup_engine = backup::Engine::new(source.path(), &mut repository)?;
|
||||||
for i in 0..files_per_backup_number {
|
for i in 0..files_per_backup_number {
|
||||||
let id = file_id(task_number, i);
|
let id = file_id(task_number, i);
|
||||||
|
|
|
@ -3,13 +3,13 @@ use tempfile::tempdir;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bakare::backup;
|
use bakare::backup;
|
||||||
use bakare::repository::Repository;
|
use bakare::repository::Repository;
|
||||||
use bakare::test::{assertions::*, source::TempSource};
|
use bakare::test::{assertions::*, source::TestSource};
|
||||||
|
|
||||||
use proptest::prelude::*;
|
use proptest::prelude::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn restore_multiple_files() -> Result<()> {
|
fn restore_multiple_files() -> Result<()> {
|
||||||
let source = TempSource::new().unwrap();
|
let source = TestSource::new().unwrap();
|
||||||
|
|
||||||
source.write_text_to_file("first", "some contents").unwrap();
|
source.write_text_to_file("first", "some contents").unwrap();
|
||||||
source.write_text_to_file("second", "some contents").unwrap();
|
source.write_text_to_file("second", "some contents").unwrap();
|
||||||
|
@ -20,7 +20,7 @@ fn restore_multiple_files() -> Result<()> {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn restore_files_after_reopening_repository() -> Result<()> {
|
fn restore_files_after_reopening_repository() -> Result<()> {
|
||||||
let source = TempSource::new().unwrap();
|
let source = TestSource::new().unwrap();
|
||||||
let repository_path = &tempdir().unwrap().into_path();
|
let repository_path = &tempdir().unwrap().into_path();
|
||||||
let restore_target = tempdir().unwrap().into_path();
|
let restore_target = tempdir().unwrap().into_path();
|
||||||
Repository::init(repository_path)?;
|
Repository::init(repository_path)?;
|
||||||
|
@ -38,7 +38,7 @@ fn restore_files_after_reopening_repository() -> Result<()> {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn restore_older_version_of_file() -> Result<()> {
|
fn restore_older_version_of_file() -> Result<()> {
|
||||||
let source = TempSource::new().unwrap();
|
let source = TestSource::new().unwrap();
|
||||||
let repository_path = tempdir().unwrap().into_path();
|
let repository_path = tempdir().unwrap().into_path();
|
||||||
Repository::init(repository_path.as_path())?;
|
Repository::init(repository_path.as_path())?;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ fn restore_older_version_of_file() -> Result<()> {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn newer_version_should_be_greater_than_earlier_version() -> Result<()> {
|
fn newer_version_should_be_greater_than_earlier_version() -> Result<()> {
|
||||||
let source = TempSource::new().unwrap();
|
let source = TestSource::new().unwrap();
|
||||||
let repository_path = tempdir().unwrap().into_path();
|
let repository_path = tempdir().unwrap().into_path();
|
||||||
Repository::init(repository_path.as_path())?;
|
Repository::init(repository_path.as_path())?;
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ fn newer_version_should_be_greater_than_earlier_version() -> Result<()> {
|
||||||
proptest! {
|
proptest! {
|
||||||
#[test]
|
#[test]
|
||||||
fn store_duplicated_files_just_once(contents in any::<[u8;3]>()) {
|
fn store_duplicated_files_just_once(contents in any::<[u8;3]>()) {
|
||||||
let source = TempSource::new().unwrap();
|
let source = TestSource::new().unwrap();
|
||||||
let repository_path = &tempdir().unwrap().into_path();
|
let repository_path = &tempdir().unwrap().into_path();
|
||||||
Repository::init(repository_path).unwrap();
|
Repository::init(repository_path).unwrap();
|
||||||
assert_eq!(data_weight(&repository_path).unwrap(), 0);
|
assert_eq!(data_weight(&repository_path).unwrap(), 0);
|
||||||
|
@ -104,7 +104,7 @@ proptest! {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn restore_latest_version_by_default() -> Result<()> {
|
fn restore_latest_version_by_default() -> Result<()> {
|
||||||
let source = TempSource::new().unwrap();
|
let source = TestSource::new().unwrap();
|
||||||
let repository_path = &tempdir().unwrap().into_path();
|
let repository_path = &tempdir().unwrap().into_path();
|
||||||
Repository::init(repository_path)?;
|
Repository::init(repository_path)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue