@@ -94,7 +94,10 @@ fn write_to_path(path: &Path, body: &str) -> Result<()> {
9494fn assert_well_formed_json ( body : & str ) {
9595 let parsed: serde_json:: Value =
9696 serde_json:: from_str ( body) . expect ( "run-output: rendered JSON must parse" ) ;
97- assert ! ( parsed. is_array( ) , "run-output: rendered JSON must be an array" ) ;
97+ assert ! (
98+ parsed. is_array( ) ,
99+ "run-output: rendered JSON must be an array"
100+ ) ;
98101 eprintln ! ( "contract: run-output OK" ) ;
99102}
100103
@@ -247,42 +250,74 @@ pub async fn top_actors(pool: &PgPool, limit: i64) -> Result<Vec<TopActor>> {
247250/// the row count matches the requested limit, the leading row's metric is
248251/// non-trivial, and the metric is monotonically non-increasing.
249252fn assert_topn_invariants < T > ( rows : & [ T ] , limit : usize , label : & str , metric : impl Fn ( & T ) -> i64 ) {
250- assert_eq ! ( rows. len( ) , limit, "{label}-row-count: expected {limit}, got {}" , rows. len( ) ) ;
253+ assert_eq ! (
254+ rows. len( ) ,
255+ limit,
256+ "{label}-row-count: expected {limit}, got {}" ,
257+ rows. len( )
258+ ) ;
251259 eprintln ! ( "contract: {label}-row-count OK" ) ;
252260
253- assert ! ( metric( & rows[ 0 ] ) >= 1 , "{label}-top-nonzero: leading row metric must be >= 1" ) ;
261+ assert ! (
262+ metric( & rows[ 0 ] ) >= 1 ,
263+ "{label}-top-nonzero: leading row metric must be >= 1"
264+ ) ;
254265 eprintln ! ( "contract: {label}-top-nonzero OK" ) ;
255266
256267 for w in rows. windows ( 2 ) {
257- assert ! ( metric( & w[ 0 ] ) >= metric( & w[ 1 ] ) , "{label}-monotonic: ORDER BY DESC violated" ) ;
268+ assert ! (
269+ metric( & w[ 0 ] ) >= metric( & w[ 1 ] ) ,
270+ "{label}-monotonic: ORDER BY DESC violated"
271+ ) ;
258272 }
259273 eprintln ! ( "contract: {label}-monotonic OK" ) ;
260274}
261275
262276fn assert_contracts_customers ( rows : & [ TopCustomer ] , limit : usize ) {
263277 assert_topn_invariants ( rows, limit, "customers" , |r| r. rental_count ) ;
264278 for r in rows {
265- assert ! ( r. customer_id > 0 , "customers-row-shape: customer_id must be positive (got {})" , r. customer_id) ;
266- assert ! ( r. name. contains( ' ' ) , "customers-row-shape: name must be 'First Last' (got {:?})" , r. name) ;
279+ assert ! (
280+ r. customer_id > 0 ,
281+ "customers-row-shape: customer_id must be positive (got {})" ,
282+ r. customer_id
283+ ) ;
284+ assert ! (
285+ r. name. contains( ' ' ) ,
286+ "customers-row-shape: name must be 'First Last' (got {:?})" ,
287+ r. name
288+ ) ;
267289 }
268290 eprintln ! ( "contract: customers-row-shape OK" ) ;
269291}
270292
271293fn assert_contracts_films ( rows : & [ TopFilm ] , limit : usize ) {
272294 assert_topn_invariants ( rows, limit, "films" , |r| r. rental_count ) ;
273295 for r in rows {
274- assert ! ( r. film_id > 0 , "films-row-shape: film_id must be positive (got {})" , r. film_id) ;
275- assert ! ( !r. title. is_empty( ) , "films-row-shape: title must be non-empty" ) ;
296+ assert ! (
297+ r. film_id > 0 ,
298+ "films-row-shape: film_id must be positive (got {})" ,
299+ r. film_id
300+ ) ;
301+ assert ! (
302+ !r. title. is_empty( ) ,
303+ "films-row-shape: title must be non-empty"
304+ ) ;
276305 }
277306 eprintln ! ( "contract: films-row-shape OK" ) ;
278307}
279308
280309fn assert_contracts_actors ( rows : & [ TopActor ] , limit : usize ) {
281310 assert_topn_invariants ( rows, limit, "actors" , |r| r. film_count ) ;
282311 for r in rows {
283- assert ! ( r. actor_id > 0 , "actors-row-shape: actor_id must be positive (got {})" , r. actor_id) ;
284- assert ! ( !r. first_name. is_empty( ) && !r. last_name. is_empty( ) ,
285- "actors-row-shape: first/last name must be non-empty" ) ;
312+ assert ! (
313+ r. actor_id > 0 ,
314+ "actors-row-shape: actor_id must be positive (got {})" ,
315+ r. actor_id
316+ ) ;
317+ assert ! (
318+ !r. first_name. is_empty( ) && !r. last_name. is_empty( ) ,
319+ "actors-row-shape: first/last name must be non-empty"
320+ ) ;
286321 }
287322 eprintln ! ( "contract: actors-row-shape OK" ) ;
288323}
@@ -292,13 +327,27 @@ mod tests {
292327 use super :: * ;
293328
294329 fn customer ( id : i32 , name : & str , count : i64 ) -> TopCustomer {
295- TopCustomer { customer_id : id, name : name. into ( ) , rental_count : count, email : None }
330+ TopCustomer {
331+ customer_id : id,
332+ name : name. into ( ) ,
333+ rental_count : count,
334+ email : None ,
335+ }
296336 }
297337 fn film ( id : i32 , title : & str , count : i64 ) -> TopFilm {
298- TopFilm { film_id : id, title : title. into ( ) , rental_count : count }
338+ TopFilm {
339+ film_id : id,
340+ title : title. into ( ) ,
341+ rental_count : count,
342+ }
299343 }
300344 fn actor ( id : i32 , first : & str , last : & str , count : i64 ) -> TopActor {
301- TopActor { actor_id : id, first_name : first. into ( ) , last_name : last. into ( ) , film_count : count }
345+ TopActor {
346+ actor_id : id,
347+ first_name : first. into ( ) ,
348+ last_name : last. into ( ) ,
349+ film_count : count,
350+ }
302351 }
303352
304353 #[ test]
@@ -340,7 +389,10 @@ mod tests {
340389
341390 #[ test]
342391 fn films_contracts_pass_on_well_formed_rows ( ) {
343- let rows = vec ! [ film( 1 , "BUCKET BROTHERHOOD" , 34 ) , film( 2 , "ROCKETEER MOTHER" , 33 ) ] ;
392+ let rows = vec ! [
393+ film( 1 , "BUCKET BROTHERHOOD" , 34 ) ,
394+ film( 2 , "ROCKETEER MOTHER" , 33 ) ,
395+ ] ;
344396 assert_contracts_films ( & rows, 2 ) ;
345397 }
346398
@@ -376,7 +428,10 @@ mod tests {
376428
377429 #[ test]
378430 fn actors_contracts_pass_on_well_formed_rows ( ) {
379- let rows = vec ! [ actor( 1 , "GINA" , "DEGENERES" , 42 ) , actor( 2 , "WALTER" , "TORN" , 41 ) ] ;
431+ let rows = vec ! [
432+ actor( 1 , "GINA" , "DEGENERES" , 42 ) ,
433+ actor( 2 , "WALTER" , "TORN" , 41 ) ,
434+ ] ;
380435 assert_contracts_actors ( & rows, 2 ) ;
381436 }
382437
@@ -419,7 +474,10 @@ mod tests {
419474 #[ tokio:: test]
420475 async fn pool_returns_error_for_unreachable_url ( ) {
421476 let result = pool ( "postgres://nobody@127.0.0.1:1/none" ) . await ;
422- assert ! ( result. is_err( ) , "unreachable URL must return Err, not panic" ) ;
477+ assert ! (
478+ result. is_err( ) ,
479+ "unreachable URL must return Err, not panic"
480+ ) ;
423481 }
424482
425483 #[ test]
@@ -458,9 +516,18 @@ mod tests {
458516 std:: fs:: write ( & blocker, "i am a file, not a directory" ) . expect ( "seed blocker" ) ;
459517 let target = blocker. join ( "inner.json" ) ;
460518 let result = write_to_path ( & target, "[]" ) ;
461- assert ! ( result. is_err( ) , "create_dir_all must fail under a regular file" ) ;
462- let msg = format ! ( "{:?}" , result. expect_err( "create_dir_all should have failed" ) ) ;
463- assert ! ( msg. contains( "failed to create directory" ) , "unexpected error: {msg}" ) ;
519+ assert ! (
520+ result. is_err( ) ,
521+ "create_dir_all must fail under a regular file"
522+ ) ;
523+ let msg = format ! (
524+ "{:?}" ,
525+ result. expect_err( "create_dir_all should have failed" )
526+ ) ;
527+ assert ! (
528+ msg. contains( "failed to create directory" ) ,
529+ "unexpected error: {msg}"
530+ ) ;
464531 std:: fs:: remove_file ( & blocker) . ok ( ) ;
465532 }
466533
0 commit comments