• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / etl / 19632084451

24 Nov 2025 11:05AM UTC coverage: 82.424% (-0.1%) from 82.529%
19632084451

Pull #464

github

web-flow
Merge dbf156d49 into 9fbcc4fc6
Pull Request #464: improve tests

31 of 57 new or added lines in 2 files covered. (54.39%)

1 existing line in 1 file now uncovered.

16357 of 19845 relevant lines covered (82.42%)

180.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.61
/etl-postgres/src/sqlx/test_utils.rs
1
use etl_config::shared::{IntoConnectOptions, PgConnectionConfig};
2
use sqlx::{Connection, Executor, PgConnection, PgPool};
3

4
/// Creates a new Postgres database and returns a connection pool.
5
///
6
/// Connects to Postgres server, creates a new database, and returns a [`PgPool`]
7
/// connected to the newly created database.
8
///
9
/// # Panics
10
/// Panics if connection or database creation fails.
11
pub async fn create_pg_database(config: &PgConnectionConfig) -> PgPool {
420✔
12
    // Create the database via a single connection.
13
    let mut connection = PgConnection::connect_with(&config.without_db())
420✔
14
        .await
420✔
15
        .expect("Failed to connect to Postgres");
420✔
16
    connection
420✔
17
        .execute(&*format!(r#"create database "{}";"#, config.name))
420✔
18
        .await
420✔
19
        .expect("Failed to create database");
420✔
20

21
    // Create a connection pool to the database.
22
    PgPool::connect_with(config.with_db())
420✔
23
        .await
420✔
24
        .expect("Failed to connect to Postgres")
420✔
25
}
420✔
26

27
/// Drops a Postgres database and terminates all connections.
28
///
29
/// Connects to Postgres server, forcefully terminates active connections
30
/// to the target database, and drops it if it exists. Used for test cleanup.
31
///
32
/// This function will not panic on errors - it logs them and continues.
33
/// This ensures test cleanup doesn't fail when databases are already gone
34
/// or connections can't be established.
35
pub async fn drop_pg_database(config: &PgConnectionConfig) {
416✔
36
    // Connect to the default database.
37
    let mut connection = match PgConnection::connect_with(&config.without_db()).await {
416✔
38
        Ok(conn) => conn,
416✔
NEW
39
        Err(e) => {
×
NEW
40
            eprintln!("warning: failed to connect to Postgres for cleanup: {}", e);
×
NEW
41
            return;
×
42
        }
43
    };
44

45
    // Forcefully terminate any remaining connections to the database.
46
    if let Err(e) = connection
416✔
47
        .execute(&*format!(
416✔
48
            r#"
416✔
49
            select pg_terminate_backend(pg_stat_activity.pid)
416✔
50
            from pg_stat_activity
416✔
51
            where pg_stat_activity.datname = '{}'
416✔
52
            and pid <> pg_backend_pid();"#,
416✔
53
            config.name
416✔
54
        ))
416✔
55
        .await
416✔
NEW
56
    {
×
NEW
57
        eprintln!(
×
NEW
58
            "warning: failed to terminate connections for database {}: {}",
×
NEW
59
            config.name, e
×
NEW
60
        );
×
61
    }
416✔
62

63
    // Drop the database.
64
    if let Err(e) = connection
416✔
65
        .execute(&*format!(r#"drop database if exists "{}";"#, config.name))
416✔
66
        .await
416✔
NEW
67
    {
×
NEW
68
        eprintln!("warning: failed to drop database {}: {}", config.name, e);
×
69
    }
416✔
70
}
416✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc