@@ -35,27 +35,41 @@ pub async fn teardown_db(db_pool: DbPool) {
3535 drop(db_pool);
3636
3737 let root_db_config = db_config.clone().database("postgres");
38- let mut connection: PgConnection = Connection::connect_with(&root_db_config).await.unwrap();
38+ let mut connection: PgConnection = Connection::connect_with(&root_db_config)
39+ .await
40+ .expect("Should be able to connect to Postgres database!");
3941
40- let test_db_name = db_config.get_database().unwrap();
42+ let test_db_name = db_config
43+ .get_database()
44+ .expect("Should be able to get the database name!");
4145
4246 let query = format!("DROP DATABASE IF EXISTS {test_db_name}");
43- connection.execute(query.as_str()).await.unwrap();
47+ connection
48+ .execute(query.as_str())
49+ .await
50+ .unwrap_or_else(|_| panic!("Could not execute DROP DATABASE {test_db_name} query!"));
4451}
4552
4653async fn prepare_db(config: &DatabaseConfig) -> DatabaseConfig {
4754 let db_config = parse_db_config(&config.url);
48- let db_name = db_config.get_database().unwrap();
55+ let db_name = db_config
56+ .get_database()
57+ .expect("Should be able to get the database name!");
4958
5059 let root_db_config = db_config.clone().database("postgres");
51- let mut connection: PgConnection = Connection::connect_with(&root_db_config).await.unwrap();
60+ let mut connection: PgConnection = Connection::connect_with(&root_db_config)
61+ .await
62+ .expect("Should be able to connect to the Postgres database!");
5263
5364 let test_db_name = build_test_db_name(db_name);
5465
5566 let query = format!("CREATE DATABASE {test_db_name} TEMPLATE {db_name}");
56- connection.execute(query.as_str()).await.unwrap();
67+ connection
68+ .execute(query.as_str())
69+ .await
70+ .unwrap_or_else(|_| panic!("Could not execute CREATE DATABASE {test_db_name} query!"));
5771
58- let regex = Regex::new(r"(.+)\ /(.+$)").unwrap( );
72+ let regex = Regex::new(r"(.+)/(.+$)").expect("Should be able to compile regex" );
5973 let test_db_url = regex.replace(&config.url, |caps: &Captures| {
6074 format!("{}/{}", &caps[1], test_db_name)
6175 });
0 commit comments