From d2b6b8e5f3e54483f269e501816b9e275d59223f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 13 Mar 2022 01:58:19 +0100 Subject: insert(): Test that an array of YAML records get inserted --- src/lib.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index f8d0032..9ee48d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,8 +54,7 @@ mod tests { let mut stmt = conn.prepare(r#" SELECT id, count, weight, description - FROM "test" - LIMIT 1; + FROM "test"; "#).unwrap(); let rows = stmt.query_map( @@ -135,6 +134,38 @@ r#"- description: >- #[test] fn inserts_multiple_records() { + let expected = vec![ + TestRecord { + id: 1, + count: 10, + weight: 33.2, + description: "First".to_owned(), + }, + TestRecord { + id: 2, + count: 12, + weight: 180.5, + description: "Second".to_owned(), + }, + ]; + + let yaml_str = format!( +r#"- description: {} + count: {} + weight: {} +- description: {} + count: {} + weight: {} +"#, + expected[0].description, + expected[0].count, + expected[0].weight, + expected[1].description, + expected[1].count, + expected[1].weight, + ); + + test_yaml_insert(&yaml_str, &expected); } #[test] -- cgit v1.2.3