Skip to content

fix: correct bug where commands hang on windows when retrieving stdout/stderr #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 6, 2024
Merged
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- linux-x64
- macos-arm64
- macos-x64
#- windows-x64
- windows-x64

include:
- platform: linux-x64
Expand All @@ -36,8 +36,8 @@ jobs:
os: macos-14
- platform: macos-x64
os: macos-13
#- platform: windows-x64
# os: windows-2022
- platform: windows-x64
os: windows-2022

steps:
- name: Checkout source code
Expand All @@ -55,6 +55,17 @@ jobs:
tool: grcov

- name: Tests
if: ${{ !startsWith(matrix.os, 'ubuntu-') }}
env:
CARGO_TERM_COLOR: always
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
RUST_LOG: "info,postgresql_archive=debug,postgresql_commands=debug,postgresql_embedded=debug"
RUST_LOG_SPAN_EVENTS: full
run: |
cargo test

- name: Tests
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
env:
CARGO_TERM_COLOR: always
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Expand Down
17 changes: 15 additions & 2 deletions postgresql_commands/src/clusterdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,15 @@ mod tests {
#[test]
fn test_builder_from() {
let command = ClusterDbBuilder::from(&TestSettings).build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGPASSWORD="password" "./clusterdb" "#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\clusterdb" "#;

assert_eq!(
r#"PGPASSWORD="password" "./clusterdb" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
format!(
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
),
command.to_command_string()
);
}
Expand All @@ -300,9 +307,15 @@ mod tests {
.pg_password("password")
.maintenance_db("postgres")
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" PGPASSWORD="password" "clusterdb" "--all" "--dbname" "dbname" "--echo" "--quiet" "--table" "table" "--verbose" "--version" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres""#,
format!(
r#"{command_prefix}"clusterdb" "--all" "--dbname" "dbname" "--echo" "--quiet" "--table" "table" "--verbose" "--version" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres""#
),
command.to_command_string()
);
}
Expand Down
17 changes: 15 additions & 2 deletions postgresql_commands/src/createdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,15 @@ mod tests {
#[test]
fn test_builder_from() {
let command = CreateDbBuilder::from(&TestSettings).build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGPASSWORD="password" "./createdb" "#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\createdb" "#;

assert_eq!(
r#"PGPASSWORD="password" "./createdb" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
format!(
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
),
command.to_command_string()
);
}
Expand Down Expand Up @@ -413,9 +420,15 @@ mod tests {
.dbname("testdb")
.description("Test Database")
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" PGPASSWORD="password" "createdb" "--tablespace" "pg_default" "--echo" "--encoding" "UTF8" "--locale" "en_US.UTF-8" "--lc-collate" "en_US.UTF-8" "--lc-ctype" "en_US.UTF-8" "--icu-locale" "en_US" "--icu-rules" "standard" "--locale-provider" "icu" "--owner" "postgres" "--strategy" "wal_log" "--template" "template0" "--version" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres" "testdb" "Test Database""#,
format!(
r#"{command_prefix}"createdb" "--tablespace" "pg_default" "--echo" "--encoding" "UTF8" "--locale" "en_US.UTF-8" "--lc-collate" "en_US.UTF-8" "--lc-ctype" "en_US.UTF-8" "--icu-locale" "en_US" "--icu-rules" "standard" "--locale-provider" "icu" "--owner" "postgres" "--strategy" "wal_log" "--template" "template0" "--version" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres" "testdb" "Test Database""#
),
command.to_command_string()
);
}
Expand Down
17 changes: 15 additions & 2 deletions postgresql_commands/src/createuser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,15 @@ mod tests {
#[test]
fn test_builder_from() {
let command = CreateUserBuilder::from(&TestSettings).build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGPASSWORD="password" "./createuser" "#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\createuser" "#;

assert_eq!(
r#"PGPASSWORD="password" "./createuser" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
format!(
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
),
command.to_command_string()
);
}
Expand Down Expand Up @@ -497,9 +504,15 @@ mod tests {
.password()
.pg_password("password")
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" PGPASSWORD="password" "createuser" "--with-admin" "admin" "--connection-limit" "10" "--createdb" "--no-createdb" "--echo" "--member-of" "member" "--inherit" "--no-inherit" "--login" "--no-login" "--with-member" "member" "--pwprompt" "--createrole" "--no-createrole" "--superuser" "--no-superuser" "--valid-until" "2021-12-31" "--version" "--interactive" "--bypassrls" "--no-bypassrls" "--replication" "--no-replication" "--help" "--host" "localhost" "--port" "5432" "--username" "username" "--no-password" "--password""#,
format!(
r#"{command_prefix}"createuser" "--with-admin" "admin" "--connection-limit" "10" "--createdb" "--no-createdb" "--echo" "--member-of" "member" "--inherit" "--no-inherit" "--login" "--no-login" "--with-member" "member" "--pwprompt" "--createrole" "--no-createrole" "--superuser" "--no-superuser" "--valid-until" "2021-12-31" "--version" "--interactive" "--bypassrls" "--no-bypassrls" "--replication" "--no-replication" "--help" "--host" "localhost" "--port" "5432" "--username" "username" "--no-password" "--password""#
),
command.to_command_string()
);
}
Expand Down
17 changes: 15 additions & 2 deletions postgresql_commands/src/dropdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,15 @@ mod tests {
#[test]
fn test_builder_from() {
let command = DropDbBuilder::from(&TestSettings).build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGPASSWORD="password" "./dropdb" "#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\dropdb" "#;

assert_eq!(
r#"PGPASSWORD="password" "./dropdb" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
format!(
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
),
command.to_command_string()
);
}
Expand All @@ -284,9 +291,15 @@ mod tests {
.maintenance_db("postgres")
.dbname("dbname")
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" PGPASSWORD="password" "dropdb" "--echo" "--force" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres" "dbname""#,
format!(
r#"{command_prefix}"dropdb" "--echo" "--force" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password" "--maintenance-db" "postgres" "dbname""#
),
command.to_command_string()
);
}
Expand Down
17 changes: 15 additions & 2 deletions postgresql_commands/src/dropuser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,15 @@ mod tests {
#[test]
fn test_builder_from() {
let command = DropUserBuilder::from(&TestSettings).build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGPASSWORD="password" "./dropuser" "#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\dropuser" "#;

assert_eq!(
r#"PGPASSWORD="password" "./dropuser" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
format!(
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
),
command.to_command_string()
);
}
Expand All @@ -245,9 +252,15 @@ mod tests {
.password()
.pg_password("password")
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" PGPASSWORD="password" "dropuser" "--echo" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password""#,
format!(
r#"{command_prefix}"dropuser" "--echo" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password""#
),
command.to_command_string()
);
}
Expand Down
15 changes: 13 additions & 2 deletions postgresql_commands/src/ecpg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ mod tests {
#[test]
fn test_builder_from() {
let command = EcpgBuilder::from(&TestSettings).build();
assert_eq!(r#""./ecpg""#, command.to_command_string());
#[cfg(not(target_os = "windows"))]
let command_prefix = r#""./ecpg""#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\ecpg""#;

assert_eq!(format!("{command_prefix}"), command.to_command_string());
}

#[test]
Expand All @@ -250,9 +255,15 @@ mod tests {
.version()
.help()
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" "ecpg" "-c" "-C" "mode" "-D" "symbol" "-h" "-i" "-I" "directory" "-o" "outfile" "-r" "behavior" "--regression" "-t" "--version" "--help""#,
format!(
r#"{command_prefix}"ecpg" "-c" "-C" "mode" "-D" "symbol" "-h" "-i" "-I" "directory" "-o" "outfile" "-r" "behavior" "--regression" "-t" "--version" "--help""#
),
command.to_command_string()
);
}
Expand Down
15 changes: 13 additions & 2 deletions postgresql_commands/src/initdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,13 @@ mod tests {
#[test]
fn test_builder_from() {
let command = InitDbBuilder::from(&TestSettings).build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#""./initdb" "#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\initdb" "#;

assert_eq!(
r#""./initdb" "--username" "postgres""#,
format!(r#"{command_prefix}"--username" "postgres""#),
command.to_command_string()
);
}
Expand Down Expand Up @@ -572,9 +577,15 @@ mod tests {
.version()
.help()
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" "initdb" "--auth" "md5" "--auth-host" "md5" "--auth-local" "md5" "--pgdata" "pgdata" "--encoding" "UTF8" "--allow-group-access" "--icu-locale" "en_US" "--icu-rules" "phonebook" "--data-checksums" "--locale" "en_US" "--lc-collate" "en_US" "--lc-ctype" "en_US" "--lc-messages" "en_US" "--lc-monetary" "en_US" "--lc-numeric" "en_US" "--lc-time" "en_US" "--no-locale" "--locale-provider" "icu" "--pwfile" ".pwfile" "--text-search-config" "english" "--username" "postgres" "--pwprompt" "--waldir" "waldir" "--wal-segsize" "1" "--set" "timezone=UTC" "--debug" "--discard-caches" "--directory" "directory" "--no-clean" "--no-sync" "--no-instructions" "--show" "--sync-only" "--version" "--help""#,
format!(
r#"{command_prefix}"initdb" "--auth" "md5" "--auth-host" "md5" "--auth-local" "md5" "--pgdata" "pgdata" "--encoding" "UTF8" "--allow-group-access" "--icu-locale" "en_US" "--icu-rules" "phonebook" "--data-checksums" "--locale" "en_US" "--lc-collate" "en_US" "--lc-ctype" "en_US" "--lc-messages" "en_US" "--lc-monetary" "en_US" "--lc-numeric" "en_US" "--lc-time" "en_US" "--no-locale" "--locale-provider" "icu" "--pwfile" ".pwfile" "--text-search-config" "english" "--username" "postgres" "--pwprompt" "--waldir" "waldir" "--wal-segsize" "1" "--set" "timezone=UTC" "--debug" "--discard-caches" "--directory" "directory" "--no-clean" "--no-sync" "--no-instructions" "--show" "--sync-only" "--version" "--help""#
),
command.to_command_string()
);
}
Expand Down
17 changes: 15 additions & 2 deletions postgresql_commands/src/oid2name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,15 @@ mod tests {
#[test]
fn test_builder_from() {
let command = Oid2NameBuilder::from(&TestSettings).build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#""./oid2name" "#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\oid2name" "#;

assert_eq!(
r#""./oid2name" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
format!(
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
),
command.to_command_string()
);
}
Expand All @@ -285,9 +292,15 @@ mod tests {
.port(5432)
.username("username")
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" "oid2name" "--filenode" "filenode" "--indexes" "--oid" "oid" "--quiet" "--tablespaces" "--system-objects" "--table" "table" "--version" "--extended" "--help" "--dbname" "dbname" "--host" "localhost" "--port" "5432" "--username" "username""#,
format!(
r#"{command_prefix}"oid2name" "--filenode" "filenode" "--indexes" "--oid" "oid" "--quiet" "--tablespaces" "--system-objects" "--table" "table" "--version" "--extended" "--help" "--dbname" "dbname" "--host" "localhost" "--port" "5432" "--username" "username""#
),
command.to_command_string()
);
}
Expand Down
17 changes: 15 additions & 2 deletions postgresql_commands/src/pg_amcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,15 @@ mod tests {
#[test]
fn test_builder_from() {
let command = PgAmCheckBuilder::from(&TestSettings).build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGPASSWORD="password" "./pg_amcheck" "#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\pg_amcheck" "#;

assert_eq!(
r#"PGPASSWORD="password" "./pg_amcheck" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
format!(
r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#
),
command.to_command_string()
);
}
Expand Down Expand Up @@ -586,9 +593,15 @@ mod tests {
.install_missing()
.help()
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" PGPASSWORD="password" "pg_amcheck" "--all" "--database" "database" "--exclude-database" "exclude_database" "--index" "index" "--exclude-index" "exclude_index" "--relation" "relation" "--exclude-relation" "exclude_relation" "--schema" "schema" "--exclude-schema" "exclude_schema" "--table" "table" "--exclude-table" "exclude_table" "--no-dependent-indexes" "--no-dependent-toast" "--no-strict-names" "--exclude-toast-pointers" "--on-error-stop" "--skip" "skip" "--startblock" "start_block" "--endblock" "end_block" "--heapallindexed" "--parent-check" "--rootdescend" "--host" "localhost" "--port" "5432" "--username" "username" "--no-password" "--password" "--maintenance-db" "maintenance_db" "--echo" "--jobs" "jobs" "--progress" "--verbose" "--version" "--install-missing" "--help""#,
format!(
r#"{command_prefix}"pg_amcheck" "--all" "--database" "database" "--exclude-database" "exclude_database" "--index" "index" "--exclude-index" "exclude_index" "--relation" "relation" "--exclude-relation" "exclude_relation" "--schema" "schema" "--exclude-schema" "exclude_schema" "--table" "table" "--exclude-table" "exclude_table" "--no-dependent-indexes" "--no-dependent-toast" "--no-strict-names" "--exclude-toast-pointers" "--on-error-stop" "--skip" "skip" "--startblock" "start_block" "--endblock" "end_block" "--heapallindexed" "--parent-check" "--rootdescend" "--host" "localhost" "--port" "5432" "--username" "username" "--no-password" "--password" "--maintenance-db" "maintenance_db" "--echo" "--jobs" "jobs" "--progress" "--verbose" "--version" "--install-missing" "--help""#
),
command.to_command_string()
);
}
Expand Down
15 changes: 13 additions & 2 deletions postgresql_commands/src/pg_archivecleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ mod tests {
#[test]
fn test_builder_from() {
let command = PgArchiveCleanupBuilder::from(&TestSettings).build();
assert_eq!(r#""./pg_archivecleanup""#, command.to_command_string());
#[cfg(not(target_os = "windows"))]
let command_prefix = r#""./pg_archivecleanup""#;
#[cfg(target_os = "windows")]
let command_prefix = r#"".\\pg_archivecleanup""#;

assert_eq!(format!("{command_prefix}"), command.to_command_string());
}

#[test]
Expand All @@ -181,9 +186,15 @@ mod tests {
.archive_location("archive_location")
.oldest_kept_wal_file("000000010000000000000001")
.build();
#[cfg(not(target_os = "windows"))]
let command_prefix = r#"PGDATABASE="database" "#;
#[cfg(target_os = "windows")]
let command_prefix = String::new();

assert_eq!(
r#"PGDATABASE="database" "pg_archivecleanup" "-d" "-n" "--version" "-x" "partial" "--help" "archive_location" "000000010000000000000001""#,
format!(
r#"{command_prefix}"pg_archivecleanup" "-d" "-n" "--version" "-x" "partial" "--help" "archive_location" "000000010000000000000001""#
),
command.to_command_string()
);
}
Expand Down
Loading