-
-
Notifications
You must be signed in to change notification settings - Fork 32
feat(tests): Add integration tests for pg_replicate #121
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
/// | ||
/// Similar to [`create_pg_database`], but additionally runs all database migrations | ||
/// from the "./migrations" directory after creation. Returns a [`PgPool`] | ||
/// connected to the newly created and migrated database. Panics if database | ||
/// creation or migration fails. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move panic docs to the Panics
section
/// | |
/// Similar to [`create_pg_database`], but additionally runs all database migrations | |
/// from the "./migrations" directory after creation. Returns a [`PgPool`] | |
/// connected to the newly created and migrated database. Panics if database | |
/// creation or migration fails. | |
/// | |
/// Similar to [`create_pg_database`], but additionally runs all database migrations | |
/// from the "./migrations" directory after creation. Returns a [`PgPool`] | |
/// connected to the newly created and migrated database. | |
/// | |
/// # Panics | |
/// | |
/// Panics if database creation or migration fails. |
|
||
async fn double_users_ages(database: &PgDatabase) { | ||
database | ||
.update_values(test_table_name("users"), &["age"], &[&"age * 2"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.update_values(test_table_name("users"), &["age"], &[&"age * 2"]) | |
.update_values(test_table_name("users"), &["age"], &["age * 2"]) |
postgres/src/sqlx/test_utils.rs
Outdated
.await | ||
.expect("Failed to create database"); | ||
|
||
// Create a connection pool to the database and run the migration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: migrations don't run here as per the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I left it from a previous impl.
postgres/src/tokio/test_utils.rs
Outdated
); | ||
self.client.execute(&create_publication_query, &[]).await?; | ||
|
||
Ok(publication_name.to_string()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can avoid returning the publication name string here as the caller already knows it.
postgres/src/tokio/test_utils.rs
Outdated
let query = format!( | ||
"SELECT {} FROM {}{}", | ||
column, | ||
table_name.as_quoted_identifier(), | ||
where_str | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For queries like these we can use sqlx macros which are much nicer than manually formatting values into a string. Another minor point is about using uppercase in SQL: we use lowercase as a convention for SQL at supabase, but not a big deal here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice, good to know! I was wondering why everything was lowercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding sqlx, we can definitely unify things for later, I initially had a split database and everything just to not have any sqlx internals within pg_replicate
but the ergonomics of sqlx
are definitely better, will create a ticket.
This PR adds a new integrations tests suite for
pg_replicate
, which allows the writing of integration tests for synchronous and asynchronous pipelines.As part of this integration tests suite, a new module
postgres
was added, to share common PostgreSQL functionality (for bothtokio_postgres
andsqlx
) that can be shared across crates (e.g., the configuration object).