Skip to content

Commit 53e527f

Browse files
committed
fix: update command tests to work on Windows
1 parent 6b3f11b commit 53e527f

37 files changed

+404
-84
lines changed

postgresql_commands/src/clusterdb.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,13 @@ mod tests {
274274
#[test]
275275
fn test_builder_from() {
276276
let command = ClusterDbBuilder::from(&TestSettings).build();
277+
#[cfg(not(target_os = "windows"))]
278+
let command_prefix = r#"PGPASSWORD="password" "./clusterdb" "#;
279+
#[cfg(target_os = "windows")]
280+
let command_prefix = r#"".\\clusterdb" "#;
281+
277282
assert_eq!(
278-
r#"PGPASSWORD="password" "./clusterdb" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
283+
format!(r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#),
279284
command.to_command_string()
280285
);
281286
}
@@ -300,9 +305,13 @@ mod tests {
300305
.pg_password("password")
301306
.maintenance_db("postgres")
302307
.build();
308+
#[cfg(not(target_os = "windows"))]
309+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
310+
#[cfg(target_os = "windows")]
311+
let command_prefix = String::new();
303312

304313
assert_eq!(
305-
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""#,
314+
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""#),
306315
command.to_command_string()
307316
);
308317
}

postgresql_commands/src/createdb.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,13 @@ mod tests {
379379
#[test]
380380
fn test_builder_from() {
381381
let command = CreateDbBuilder::from(&TestSettings).build();
382+
#[cfg(not(target_os = "windows"))]
383+
let command_prefix = r#"PGPASSWORD="password" "./createdb" "#;
384+
#[cfg(target_os = "windows")]
385+
let command_prefix = r#"".\\createdb" "#;
386+
382387
assert_eq!(
383-
r#"PGPASSWORD="password" "./createdb" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
388+
format!(r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#),
384389
command.to_command_string()
385390
);
386391
}
@@ -413,9 +418,13 @@ mod tests {
413418
.dbname("testdb")
414419
.description("Test Database")
415420
.build();
421+
#[cfg(not(target_os = "windows"))]
422+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
423+
#[cfg(target_os = "windows")]
424+
let command_prefix = String::new();
416425

417426
assert_eq!(
418-
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""#,
427+
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""#),
419428
command.to_command_string()
420429
);
421430
}

postgresql_commands/src/createuser.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,13 @@ mod tests {
456456
#[test]
457457
fn test_builder_from() {
458458
let command = CreateUserBuilder::from(&TestSettings).build();
459+
#[cfg(not(target_os = "windows"))]
460+
let command_prefix = r#"PGPASSWORD="password" "./createuser" "#;
461+
#[cfg(target_os = "windows")]
462+
let command_prefix = r#"".\\createuser" "#;
463+
459464
assert_eq!(
460-
r#"PGPASSWORD="password" "./createuser" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
465+
format!(r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#),
461466
command.to_command_string()
462467
);
463468
}
@@ -497,9 +502,13 @@ mod tests {
497502
.password()
498503
.pg_password("password")
499504
.build();
505+
#[cfg(not(target_os = "windows"))]
506+
let command_prefix = r#"PGPASSWORD="password" "#;
507+
#[cfg(target_os = "windows")]
508+
let command_prefix = String::new();
500509

501510
assert_eq!(
502-
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""#,
511+
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""#),
503512
command.to_command_string()
504513
);
505514
}

postgresql_commands/src/dropdb.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,13 @@ mod tests {
259259
#[test]
260260
fn test_builder_from() {
261261
let command = DropDbBuilder::from(&TestSettings).build();
262+
#[cfg(not(target_os = "windows"))]
263+
let command_prefix = r#"PGPASSWORD="password" "./dropdb" "#;
264+
#[cfg(target_os = "windows")]
265+
let command_prefix = r#"".\\dropdb" "#;
266+
262267
assert_eq!(
263-
r#"PGPASSWORD="password" "./dropdb" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
268+
format!(r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#),
264269
command.to_command_string()
265270
);
266271
}
@@ -284,9 +289,13 @@ mod tests {
284289
.maintenance_db("postgres")
285290
.dbname("dbname")
286291
.build();
292+
#[cfg(not(target_os = "windows"))]
293+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
294+
#[cfg(target_os = "windows")]
295+
let command_prefix = String::new();
287296

288297
assert_eq!(
289-
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""#,
298+
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""#),
290299
command.to_command_string()
291300
);
292301
}

postgresql_commands/src/dropuser.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,13 @@ mod tests {
223223
#[test]
224224
fn test_builder_from() {
225225
let command = DropUserBuilder::from(&TestSettings).build();
226+
#[cfg(not(target_os = "windows"))]
227+
let command_prefix = r#"PGPASSWORD="password" "./dropuser" "#;
228+
#[cfg(target_os = "windows")]
229+
let command_prefix = r#"".\\dropuser" "#;
230+
226231
assert_eq!(
227-
r#"PGPASSWORD="password" "./dropuser" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
232+
format!(r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#),
228233
command.to_command_string()
229234
);
230235
}
@@ -245,9 +250,13 @@ mod tests {
245250
.password()
246251
.pg_password("password")
247252
.build();
253+
#[cfg(not(target_os = "windows"))]
254+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
255+
#[cfg(target_os = "windows")]
256+
let command_prefix = String::new();
248257

249258
assert_eq!(
250-
r#"PGDATABASE="database" PGPASSWORD="password" "dropuser" "--echo" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password""#,
259+
format!(r#"{command_prefix}"dropuser" "--echo" "--interactive" "--version" "--if-exists" "--help" "--host" "localhost" "--port" "5432" "--username" "postgres" "--no-password" "--password""#),
251260
command.to_command_string()
252261
);
253262
}

postgresql_commands/src/ecpg.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,12 @@ mod tests {
230230
#[test]
231231
fn test_builder_from() {
232232
let command = EcpgBuilder::from(&TestSettings).build();
233-
assert_eq!(r#""./ecpg""#, command.to_command_string());
233+
#[cfg(not(target_os = "windows"))]
234+
let command_prefix = r#"PGPASSWORD="password" "./ecpg""#;
235+
#[cfg(target_os = "windows")]
236+
let command_prefix = r#"".\\ecpg""#;
237+
238+
assert_eq!(format!("{command_prefix}"), command.to_command_string());
234239
}
235240

236241
#[test]
@@ -250,9 +255,13 @@ mod tests {
250255
.version()
251256
.help()
252257
.build();
258+
#[cfg(not(target_os = "windows"))]
259+
let command_prefix = r#"PGDATABASE="database" "#;
260+
#[cfg(target_os = "windows")]
261+
let command_prefix = String::new();
253262

254263
assert_eq!(
255-
r#"PGDATABASE="database" "ecpg" "-c" "-C" "mode" "-D" "symbol" "-h" "-i" "-I" "directory" "-o" "outfile" "-r" "behavior" "--regression" "-t" "--version" "--help""#,
264+
format!(r#"{command_prefix}"ecpg" "-c" "-C" "mode" "-D" "symbol" "-h" "-i" "-I" "directory" "-o" "outfile" "-r" "behavior" "--regression" "-t" "--version" "--help""#),
256265
command.to_command_string()
257266
);
258267
}

postgresql_commands/src/initdb.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,13 @@ mod tests {
526526
#[test]
527527
fn test_builder_from() {
528528
let command = InitDbBuilder::from(&TestSettings).build();
529+
#[cfg(not(target_os = "windows"))]
530+
let command_prefix = r#""./initdb" "#;
531+
#[cfg(target_os = "windows")]
532+
let command_prefix = r#"".\\initdb" "#;
533+
529534
assert_eq!(
530-
r#""./initdb" "--username" "postgres""#,
535+
format!(r#"{command_prefix}"--username" "postgres""#),
531536
command.to_command_string()
532537
);
533538
}
@@ -572,9 +577,13 @@ mod tests {
572577
.version()
573578
.help()
574579
.build();
580+
#[cfg(not(target_os = "windows"))]
581+
let command_prefix = r#"PGDATABASE="database" "#;
582+
#[cfg(target_os = "windows")]
583+
let command_prefix = String::new();
575584

576585
assert_eq!(
577-
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""#,
586+
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""#),
578587
command.to_command_string()
579588
);
580589
}

postgresql_commands/src/oid2name.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,13 @@ mod tests {
260260
#[test]
261261
fn test_builder_from() {
262262
let command = Oid2NameBuilder::from(&TestSettings).build();
263+
#[cfg(not(target_os = "windows"))]
264+
let command_prefix = r#""./oid2name" "#;
265+
#[cfg(target_os = "windows")]
266+
let command_prefix = r#"".\\oid2name" "#;
267+
263268
assert_eq!(
264-
r#""./oid2name" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
269+
format!(r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#),
265270
command.to_command_string()
266271
);
267272
}
@@ -285,9 +290,13 @@ mod tests {
285290
.port(5432)
286291
.username("username")
287292
.build();
293+
#[cfg(not(target_os = "windows"))]
294+
let command_prefix = r#"PGDATABASE="database" "#;
295+
#[cfg(target_os = "windows")]
296+
let command_prefix = String::new();
288297

289298
assert_eq!(
290-
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""#,
299+
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""#),
291300
command.to_command_string()
292301
);
293302
}

postgresql_commands/src/pg_amcheck.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,13 @@ mod tests {
539539
#[test]
540540
fn test_builder_from() {
541541
let command = PgAmCheckBuilder::from(&TestSettings).build();
542+
#[cfg(not(target_os = "windows"))]
543+
let command_prefix = r#"PGPASSWORD="password" "./pg_amcheck" "#;
544+
#[cfg(target_os = "windows")]
545+
let command_prefix = r#"".\\pg_amcheck" "#;
546+
542547
assert_eq!(
543-
r#"PGPASSWORD="password" "./pg_amcheck" "--host" "localhost" "--port" "5432" "--username" "postgres""#,
548+
format!(r#"{command_prefix}"--host" "localhost" "--port" "5432" "--username" "postgres""#),
544549
command.to_command_string()
545550
);
546551
}
@@ -586,9 +591,13 @@ mod tests {
586591
.install_missing()
587592
.help()
588593
.build();
594+
#[cfg(not(target_os = "windows"))]
595+
let command_prefix = r#"PGDATABASE="database" PGPASSWORD="password" "#;
596+
#[cfg(target_os = "windows")]
597+
let command_prefix = String::new();
589598

590599
assert_eq!(
591-
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""#,
600+
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""#),
592601
command.to_command_string()
593602
);
594603
}

postgresql_commands/src/pg_archivecleanup.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ mod tests {
166166
#[test]
167167
fn test_builder_from() {
168168
let command = PgArchiveCleanupBuilder::from(&TestSettings).build();
169-
assert_eq!(r#""./pg_archivecleanup""#, command.to_command_string());
169+
#[cfg(not(target_os = "windows"))]
170+
let command_prefix = r#""./pg_archivecleanup""#;
171+
#[cfg(target_os = "windows")]
172+
let command_prefix = r#"".\\pg_archivecleanup""#;
173+
174+
assert_eq!(format!("{command_prefix}"), command.to_command_string());
170175
}
171176

172177
#[test]
@@ -181,9 +186,13 @@ mod tests {
181186
.archive_location("archive_location")
182187
.oldest_kept_wal_file("000000010000000000000001")
183188
.build();
189+
#[cfg(not(target_os = "windows"))]
190+
let command_prefix = r#"PGDATABASE="database" "#;
191+
#[cfg(target_os = "windows")]
192+
let command_prefix = String::new();
184193

185194
assert_eq!(
186-
r#"PGDATABASE="database" "pg_archivecleanup" "-d" "-n" "--version" "-x" "partial" "--help" "archive_location" "000000010000000000000001""#,
195+
format!(r#"{command_prefix}"pg_archivecleanup" "-d" "-n" "--version" "-x" "partial" "--help" "archive_location" "000000010000000000000001""#),
187196
command.to_command_string()
188197
);
189198
}

0 commit comments

Comments
 (0)