Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ impl PgTempDB {

let load_output = std::process::Command::new("psql")
.arg(self.connection_uri())
.args(["--file", path_str])
.args([
"--file",
path_str,
"--set",
"ON_ERROR_STOP=1",
"--single-transaction",
])
.output()
.expect("failed to start psql. Is it installed and on your path?");

Expand Down
21 changes: 21 additions & 0 deletions tests/dump.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Tests for the dump and restore functionality

use std::io::Write;

use pgtemp::PgTempDB;
use sqlx::postgres::PgConnection;
use sqlx::prelude::*;
Expand Down Expand Up @@ -75,3 +77,22 @@ async fn dump_and_restore() {
assert_eq!(id, 10);
assert_eq!(name, "example name 9");
}

#[tokio::test]
/// make sure that we correctly error on bad database dumps.
#[should_panic(expected = "syntax error at or near \\\"INVALID\\")]
async fn panic_on_load_error() {
let temp = tempfile::tempdir().unwrap();
let db_dump_path = temp.path().join("dump.sql");

// Create some bad database dumps
let mut f = std::fs::File::create(&db_dump_path).unwrap();
f.write_all(b"INVALID SQL").unwrap();
f.flush().expect("Failed to flush file");

// Try to load it (it should fail)
PgTempDB::builder()
.load_database(&db_dump_path)
.start_async()
.await;
}