Skip to content

Commit

Permalink
Use fold and write! to concatenate a big string
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljharvey committed Oct 31, 2023
1 parent 671f9dd commit 902c079
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
9 changes: 3 additions & 6 deletions crates/tests/databases-tests/src/capabilities_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#[cfg(test)]
mod capabilities_tests {
#[tokio::test]
async fn get_capabilities() {
insta::assert_json_snapshot!(ndc_postgres::capabilities::get_capabilities());
}
#[tokio::test]
async fn get_capabilities() {
insta::assert_json_snapshot!(ndc_postgres::capabilities::get_capabilities());
}
17 changes: 9 additions & 8 deletions crates/tests/tests-common/src/schemas.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Write;
/// Checks that a given value conforms to the schema generated by `schemars`.
///
/// Panics with a human-readable error if the value does not conform, or if the
Expand All @@ -17,14 +18,14 @@ pub fn check_value_conforms_to_schema<T: schemars::JsonSchema>(value: serde_json
Err(errors) => {
panic!(
"The configuration does not conform to the schema.\n{}",
errors
.map(|error| {
format!(
"{}\ninstance path: {}\nschema path: {}\n\n",
error, error.instance_path, error.schema_path
)
})
.collect::<String>()
errors.fold(String::new(), |mut str, error| {
let _ = write!(
str,
"{}\ninstance path: {}\nschema path: {}\n\n",
error, error.instance_path, error.schema_path
);
str
})
)
}
}
Expand Down

0 comments on commit 902c079

Please sign in to comment.