(config: &DatabaseSettings)
| 229 | } |
| 230 | |
| 231 | async fn configure_database(config: &DatabaseSettings) -> PgPool { |
| 232 | // Create database |
| 233 | let maintenance_settings = DatabaseSettings { |
| 234 | database_name: "postgres".to_string(), |
| 235 | username: "postgres".to_string(), |
| 236 | password: Secret::new("password".to_string()), |
| 237 | ..config.clone() |
| 238 | }; |
| 239 | let mut connection = PgConnection::connect_with(&maintenance_settings.connect_options()) |
| 240 | .await |
| 241 | .expect("Failed to connect to Postgres"); |
| 242 | connection |
| 243 | .execute(format!(r#"CREATE DATABASE "{}";"#, config.database_name).as_str()) |
| 244 | .await |
| 245 | .expect("Failed to create database."); |
| 246 | |
| 247 | // Migrate database |
| 248 | let connection_pool = PgPool::connect_with(config.connect_options()) |
| 249 | .await |
| 250 | .expect("Failed to connect to Postgres."); |
| 251 | sqlx::migrate!("./migrations") |
| 252 | .run(&connection_pool) |
| 253 | .await |
| 254 | .expect("Failed to migrate the database"); |
| 255 | connection_pool |
| 256 | } |
| 257 | |
| 258 | pub struct TestUser { |
| 259 | user_id: Uuid, |
no test coverage detected