port data weight test to proptest
This commit is contained in:
parent
6629977515
commit
8ea7e3d950
2 changed files with 15 additions and 20 deletions
|
@ -173,31 +173,26 @@ impl<'a> Repository<'a> {
|
||||||
mod must {
|
mod must {
|
||||||
use super::Repository;
|
use super::Repository;
|
||||||
use crate::test::source::TempSource;
|
use crate::test::source::TempSource;
|
||||||
use anyhow::Result;
|
use proptest::prelude::*;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
#[test]
|
proptest! {
|
||||||
fn have_size_equal_to_sum_of_sizes_of_backed_up_files() -> Result<()> {
|
|
||||||
let source = TempSource::new().unwrap();
|
|
||||||
let repository_path = tempdir().unwrap().into_path();
|
|
||||||
Repository::init(&repository_path)?;
|
|
||||||
|
|
||||||
let file_size1 = 13;
|
#[test]
|
||||||
let file_size2 = 27;
|
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 repository_path = tempdir().unwrap().into_path();
|
||||||
|
Repository::init(&repository_path).unwrap();
|
||||||
|
|
||||||
let mut backup_repository = Repository::open(&repository_path)?;
|
let mut backup_repository = Repository::open(&repository_path).unwrap();
|
||||||
source.write_random_bytes_to_file("file1", file_size1)?;
|
source.write_random_bytes_to_file("file1", file_size1)?;
|
||||||
backup_repository.store(&source.file_path("file1"))?;
|
backup_repository.store(&source.file_path("file1")).unwrap();
|
||||||
|
|
||||||
source.write_random_bytes_to_file("file2", file_size2)?;
|
source.write_random_bytes_to_file("file2", file_size2)?;
|
||||||
backup_repository.store(&source.file_path("file2"))?;
|
backup_repository.store(&source.file_path("file2")).unwrap();
|
||||||
|
|
||||||
assert_eq!((file_size1 + file_size2) as u64, backup_repository.data_weight()?);
|
assert_eq!(file_size1 + file_size2, backup_repository.data_weight().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
backup_repository.save_index()?;
|
|
||||||
|
|
||||||
assert_eq!((file_size1 + file_size2) as u64, backup_repository.data_weight()?);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl TempSource {
|
||||||
self.write_bytes_to_file(filename, text.as_bytes())
|
self.write_bytes_to_file(filename, text.as_bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_random_bytes_to_file(&self, filename: &str, size: usize) -> Result<(), Error> {
|
pub fn write_random_bytes_to_file(&self, filename: &str, size: u64) -> Result<(), Error> {
|
||||||
let random_bytes: Vec<u8> = (0..size).map(|_| rand::random::<u8>()).collect();
|
let random_bytes: Vec<u8> = (0..size).map(|_| rand::random::<u8>()).collect();
|
||||||
self.write_bytes_to_file(filename, &random_bytes)?;
|
self.write_bytes_to_file(filename, &random_bytes)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue