-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1. improve junit-mock for testing #107
Conversation
✅ 76 passed ⋅ (learn more) |
impl Default for Options { | ||
fn default() -> Self { | ||
Options::try_parse_from([""]).unwrap() | ||
} | ||
} | ||
|
||
#[test] | ||
fn options_can_be_defaulted_without_panicing() { | ||
Options::default(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removes the need for unwrap
ing anytime we need to create options in tests or elsewhere
|
||
/// Timestamp for all data to be based on, defaults to now | ||
#[arg(long)] | ||
pub timestamp: Option<DateTime<FixedOffset>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows creating more deterministic mocks which is great for validation checking
|
||
/// The chance of a system out message being added to the test rerun | ||
#[arg(long, value_parser = clap::value_parser!(u8).range(0..=100), default_value = "50")] | ||
pub test_rerun_sys_out_percentage: u8, | ||
|
||
/// Inclusive range of time between test case timestamps | ||
#[arg(long, num_args = 1..=2, value_names = ["DURATION_RANGE_START", "DURATION_RANGE_END"], default_values = ["30s", "1m"])] | ||
pub test_rerun_duration_range: Vec<humantime::Duration>, | ||
|
||
/// The chance of a system error message being added to the test rerun | ||
#[arg(long, value_parser = clap::value_parser!(u8).range(0..=100), default_value = "50")] | ||
pub test_rerun_sys_err_percentage: u8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some extra options since we want to try parsing these later on in tests
) -> Result<Vec<PathBuf>> { | ||
reports.as_ref().iter().enumerate().try_fold( | ||
Vec::new(), | ||
|mut acc, (i, report)| -> Result<Vec<PathBuf>> { | ||
let path = directory.as_ref().join(format!("junit-{}.xml", i)); | ||
let file = File::create(&path)?; | ||
report.serialize(file)?; | ||
acc.push(path); | ||
Ok(acc) | ||
}, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes it easier to iterate over generated files instead of hard-coding paths in tests
improves junit-mocking for better tests, especially ones concerning validation