From 902c079ed9980bbb92790cd515666c36c7a1ec35 Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Tue, 31 Oct 2023 11:16:52 +0000 Subject: [PATCH] Use fold and write! to concatenate a big string --- .../databases-tests/src/capabilities_tests.rs | 9 +++------ ...__capabilities_tests__get_capabilities.snap} | 0 crates/tests/tests-common/src/schemas.rs | 17 +++++++++-------- 3 files changed, 12 insertions(+), 14 deletions(-) rename crates/tests/databases-tests/src/snapshots/{databases_tests__capabilities_tests__capabilities_tests__get_capabilities.snap => databases_tests__capabilities_tests__get_capabilities.snap} (100%) diff --git a/crates/tests/databases-tests/src/capabilities_tests.rs b/crates/tests/databases-tests/src/capabilities_tests.rs index c20574c76..69c4885af 100644 --- a/crates/tests/databases-tests/src/capabilities_tests.rs +++ b/crates/tests/databases-tests/src/capabilities_tests.rs @@ -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()); } diff --git a/crates/tests/databases-tests/src/snapshots/databases_tests__capabilities_tests__capabilities_tests__get_capabilities.snap b/crates/tests/databases-tests/src/snapshots/databases_tests__capabilities_tests__get_capabilities.snap similarity index 100% rename from crates/tests/databases-tests/src/snapshots/databases_tests__capabilities_tests__capabilities_tests__get_capabilities.snap rename to crates/tests/databases-tests/src/snapshots/databases_tests__capabilities_tests__get_capabilities.snap diff --git a/crates/tests/tests-common/src/schemas.rs b/crates/tests/tests-common/src/schemas.rs index 598cc6271..5b89dd946 100644 --- a/crates/tests/tests-common/src/schemas.rs +++ b/crates/tests/tests-common/src/schemas.rs @@ -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 @@ -17,14 +18,14 @@ pub fn check_value_conforms_to_schema(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::() + errors.fold(String::new(), |mut str, error| { + let _ = write!( + str, + "{}\ninstance path: {}\nschema path: {}\n\n", + error, error.instance_path, error.schema_path + ); + str + }) ) } }