Try to add some code for test error fuzzing

it doesn't compile, unfortunately, so it's all commented out
This commit is contained in:
Savanni D'Gerinel 2022-11-20 12:43:33 -05:00
parent 45df1233e5
commit 95a597c8ea
1 changed files with 26 additions and 1 deletions

View File

@ -1,3 +1,4 @@
use rand::prelude::Distribution;
use thiserror::Error; use thiserror::Error;
/// This struct covers *fatal* errors for the application. Cross-functional things like full disks, /// This struct covers *fatal* errors for the application. Cross-functional things like full disks,
@ -13,6 +14,11 @@ pub enum FatalError {
Io(std::io::Error), Io(std::io::Error),
} }
/*
#[cfg(test)]
const FATAL_ERRORS: [FatalError; 2] = [FatalError::DatabaseInconsistency, FatalError::DiskFull];
*/
pub type AppResult<A, E> = Result<Result<A, E>, FatalError>; pub type AppResult<A, E> = Result<Result<A, E>, FatalError>;
pub fn ok<A, E>(val: A) -> AppResult<A, E> { pub fn ok<A, E>(val: A) -> AppResult<A, E> {
@ -27,7 +33,26 @@ pub fn fatal<A, E>(err: FatalError) -> AppResult<A, E> {
Err(err) Err(err)
} }
/*
#[cfg(test)] #[cfg(test)]
pub fn maybe_fail<E>(possible_errors: Vec<E>) -> AppResult<(), E> { use rand::{distributions::Uniform, thread_rng, Rng};
*/
#[cfg(test)]
pub fn maybe_fail<E>(_module_errors: Vec<E>) -> AppResult<(), E> {
/*
let percentage = Uniform::new(0, 100);
let module_error_dist = Uniform::new(0, module_errors.len());
let fatal_error_dist = Uniform::new(0, FATAL_ERRORS.len());
if thread_rng().sample(percentage) < 10 {
if module_errors.len() > 0 && thread_rng().sample(percentage) < 75 {
// return Ok(Err(module_errors[thread_rng().sample(module_error_dist)]));
return ok(());
} else {
return Err(FATAL_ERRORS[thread_rng().sample(fatal_error_dist)]);
}
}
*/
ok(()) ok(())
} }