File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -376,3 +376,32 @@ fn generate_lock_id(database_name: &str) -> i64 {
376376 // 0x3d32ad9e chosen by fair dice roll
377377 0x3d32ad9e * ( CRC_IEEE . checksum ( database_name. as_bytes ( ) ) as i64 )
378378}
379+
380+ #[ cfg( test) ]
381+ mod tests {
382+ use super :: parse_for_maintenance;
383+
384+ #[ test]
385+ fn test_parse_for_maintenance ( ) {
386+ let ( opts, db) = parse_for_maintenance ( "postgres://user:pass@host/mydb" ) . unwrap ( ) ;
387+ assert_eq ! ( opts. database. as_deref( ) , Some ( "postgres" ) ) ;
388+ assert_eq ! ( db, "mydb" ) ;
389+
390+ let ( opts, db) = parse_for_maintenance ( "postgres://user:pass@host/postgres" ) . unwrap ( ) ;
391+ assert_eq ! ( opts. database. as_deref( ) , Some ( "template1" ) ) ;
392+ assert_eq ! ( db, "postgres" ) ;
393+
394+ let ( opts, db) =
395+ parse_for_maintenance ( "postgres://user:pass@host/mydb?maintenance_database=defaultdb" )
396+ . unwrap ( ) ;
397+ assert_eq ! ( opts. database. as_deref( ) , Some ( "defaultdb" ) ) ;
398+ assert_eq ! ( db, "mydb" ) ;
399+
400+ let ( opts, db) = parse_for_maintenance (
401+ "postgres://user:pass@host/mydb?sslmode=require&maintenance_database=defaultdb" ,
402+ )
403+ . unwrap ( ) ;
404+ assert_eq ! ( opts. database. as_deref( ) , Some ( "defaultdb" ) ) ;
405+ assert_eq ! ( db, "mydb" ) ;
406+ }
407+ }
You can’t perform that action at this time.
0 commit comments