Skip to content
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

Merged
merged 5 commits into from
Oct 2, 2024

Conversation

dfrankland
Copy link
Member

@dfrankland dfrankland commented Oct 1, 2024

improves junit-mocking for better tests, especially ones concerning validation

@dfrankland dfrankland changed the title improve junit-mock for testing 1. improve junit-mock for testing Oct 1, 2024
Copy link

trunk-staging-io bot commented Oct 1, 2024

✅ 76 passed ⋅ (learn more)

settingsdocs ⋅ learn more about trunk.io

Comment on lines +73 to +82
impl Default for Options {
fn default() -> Self {
Options::try_parse_from([""]).unwrap()
}
}

#[test]
fn options_can_be_defaulted_without_panicing() {
Options::default();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes the need for unwraping anytime we need to create options in tests or elsewhere

Comment on lines +90 to +93

/// Timestamp for all data to be based on, defaults to now
#[arg(long)]
pub timestamp: Option<DateTime<FixedOffset>>,
Copy link
Member Author

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

Comment on lines +192 to +203

/// 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,
Copy link
Member Author

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

Comment on lines +290 to +300
) -> 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)
},
)
Copy link
Member Author

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

@dfrankland dfrankland marked this pull request as ready for review October 1, 2024 23:56
@dfrankland dfrankland requested review from riya-n and gnalh October 1, 2024 23:57
@dfrankland dfrankland merged commit 4cf2c3e into main Oct 2, 2024
6 checks passed
@dfrankland dfrankland deleted the dylan/improve-junit-mock-for-testing branch October 2, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants