better name for the test source

This commit is contained in:
Cyryl Płotnicki 2020-11-28 12:22:13 +00:00
parent 9514d1b341
commit f9613cb266
5 changed files with 35 additions and 16 deletions

View file

@ -172,7 +172,7 @@ impl<'a> Repository<'a> {
#[cfg(test)]
mod must {
use super::Repository;
use crate::test::source::TempSource;
use crate::test::source::TestSource;
use proptest::prelude::*;
use tempfile::tempdir;
@ -180,7 +180,7 @@ mod must {
#[test]
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();
Repository::init(&repository_path).unwrap();

View file

@ -5,7 +5,7 @@ use std::path::Path;
use tempfile::tempdir;
use walkdir::WalkDir;
use super::source::TempSource;
use super::source::TestSource;
use crate::repository::{item::RepositoryItem, ItemId, Repository};
use crate::{backup, restore};
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(
source: &TempSource,
source: &TestSource,
repository_path: &Path,
source_file_relative_path: &str,
contents: &str,
@ -100,7 +100,7 @@ pub fn backup_file_with_text_contents(
}
pub fn backup_file_with_byte_contents(
source: &TempSource,
source: &TestSource,
repository_path: &Path,
source_file_relative_path: &str,
contents: &[u8],

View file

@ -7,11 +7,11 @@ use std::path::PathBuf;
use tempfile::tempdir;
use tempfile::TempDir;
pub struct TempSource {
pub struct TestSource {
directory: TempDir,
}
impl TempSource {
impl TestSource {
pub fn new() -> Result<Self, Error> {
Ok(Self { directory: tempdir()? })
}
@ -39,3 +39,22 @@ impl TempSource {
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(())
}
}

View file

@ -3,7 +3,7 @@ use std::path::Path;
use anyhow::Result;
use bakare::repository::Repository;
use bakare::test::{assertions::*, source::TempSource};
use bakare::test::{assertions::*, source::TestSource};
use bakare::{backup, restore};
use nix::sys::wait::{waitpid, WaitStatus};
use nix::unistd::{fork, ForkResult};
@ -77,7 +77,7 @@ where
T: AsRef<Path> + Sync,
{
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)?;
for i in 0..files_per_backup_number {
let id = file_id(task_number, i);

View file

@ -3,13 +3,13 @@ use tempfile::tempdir;
use anyhow::Result;
use bakare::backup;
use bakare::repository::Repository;
use bakare::test::{assertions::*, source::TempSource};
use bakare::test::{assertions::*, source::TestSource};
use proptest::prelude::*;
#[test]
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("second", "some contents").unwrap();
@ -20,7 +20,7 @@ fn restore_multiple_files() -> Result<()> {
#[test]
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 restore_target = tempdir().unwrap().into_path();
Repository::init(repository_path)?;
@ -38,7 +38,7 @@ fn restore_files_after_reopening_repository() -> Result<()> {
#[test]
fn restore_older_version_of_file() -> Result<()> {
let source = TempSource::new().unwrap();
let source = TestSource::new().unwrap();
let repository_path = tempdir().unwrap().into_path();
Repository::init(repository_path.as_path())?;
@ -59,7 +59,7 @@ fn restore_older_version_of_file() -> Result<()> {
#[test]
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();
Repository::init(repository_path.as_path())?;
@ -84,7 +84,7 @@ fn newer_version_should_be_greater_than_earlier_version() -> Result<()> {
proptest! {
#[test]
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();
Repository::init(repository_path).unwrap();
assert_eq!(data_weight(&repository_path).unwrap(), 0);
@ -104,7 +104,7 @@ proptest! {
#[test]
fn restore_latest_version_by_default() -> Result<()> {
let source = TempSource::new().unwrap();
let source = TestSource::new().unwrap();
let repository_path = &tempdir().unwrap().into_path();
Repository::init(repository_path)?;