feat(test): connecting to PostgreSQL
- rename the database name in the configuration.yaml
This commit is contained in:
parent
38f9646526
commit
46ac102adc
@ -4,4 +4,4 @@ database:
|
||||
port: 5432
|
||||
username: "postgres"
|
||||
password: "password"
|
||||
database_name: "email_newsletter_api"
|
||||
database_name: "newsletter"
|
||||
|
@ -23,3 +23,12 @@ pub fn get_configuration() -> Result<Settings, config::ConfigError> {
|
||||
|
||||
settings.try_deserialize::<Settings>()
|
||||
}
|
||||
|
||||
impl DatabaseSettings {
|
||||
pub fn connection_string(&self) -> String {
|
||||
format!(
|
||||
"postgres://{}:{}@{}:{}/{}",
|
||||
self.username, self.password, self.host, self.port, self.database_name
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,21 @@ mod test_utils;
|
||||
|
||||
use test_utils::spawn_app;
|
||||
|
||||
use email_newsletter_api::configuration::{self, get_configuration};
|
||||
use sqlx::{Connection, PgConnection};
|
||||
|
||||
#[tokio::test]
|
||||
async fn subscribe_returns_a_200_for_valid_form_data() {
|
||||
let server_address = spawn_app();
|
||||
|
||||
let configuration = get_configuration().expect("Failed to read configuration");
|
||||
|
||||
let postgres_connection_string = configuration.database.connection_string();
|
||||
|
||||
let connection = PgConnection::connect(&postgres_connection_string)
|
||||
.await
|
||||
.expect("Failed to connect to Postgres");
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
|
||||
let body = "name=le%20test&email=le_test%40gmail.com";
|
||||
|
Loading…
x
Reference in New Issue
Block a user