From 95a597c8eac22310720203cbd58fc01d4968fd6f Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 20 Nov 2022 12:43:33 -0500 Subject: [PATCH] Try to add some code for test error fuzzing it doesn't compile, unfortunately, so it's all commented out --- server/src/errors.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/server/src/errors.rs b/server/src/errors.rs index 36d4e02..50d5774 100644 --- a/server/src/errors.rs +++ b/server/src/errors.rs @@ -1,3 +1,4 @@ +use rand::prelude::Distribution; use thiserror::Error; /// 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), } +/* +#[cfg(test)] +const FATAL_ERRORS: [FatalError; 2] = [FatalError::DatabaseInconsistency, FatalError::DiskFull]; +*/ + pub type AppResult = Result, FatalError>; pub fn ok(val: A) -> AppResult { @@ -27,7 +33,26 @@ pub fn fatal(err: FatalError) -> AppResult { Err(err) } +/* #[cfg(test)] -pub fn maybe_fail(possible_errors: Vec) -> AppResult<(), E> { +use rand::{distributions::Uniform, thread_rng, Rng}; +*/ + +#[cfg(test)] +pub fn maybe_fail(_module_errors: Vec) -> 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(()) }