Skip to content

Commit 5507677

Browse files
Merge pull request #50 from theseus-rs/add-command-integration-test
test: add command integration test
2 parents bb44bfd + 26ad16c commit 5507677

File tree

3 files changed

+57
-15
lines changed

3 files changed

+57
-15
lines changed

Cargo.lock

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

postgresql_embedded/src/postgresql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use postgresql_commands::initdb::InitDbBuilder;
77
use postgresql_commands::pg_ctl::Mode::{Start, Stop};
88
use postgresql_commands::pg_ctl::PgCtlBuilder;
99
use postgresql_commands::pg_ctl::ShutdownMode::Fast;
10+
use postgresql_commands::psql::PsqlBuilder;
1011
#[cfg(feature = "tokio")]
1112
use postgresql_commands::AsyncCommandExecutor;
1213
use postgresql_commands::CommandBuilder;
@@ -22,7 +23,6 @@ use std::str::FromStr;
2223
use tracing::{debug, instrument};
2324

2425
use crate::Error::{CreateDatabaseError, DatabaseExistsError, DropDatabaseError};
25-
use postgresql_commands::psql::PsqlBuilder;
2626

2727
#[cfg(feature = "bundled")]
2828
lazy_static::lazy_static! {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use postgresql_commands::pg_dump::PgDumpBuilder;
2+
use postgresql_commands::psql::PsqlBuilder;
3+
use postgresql_commands::{CommandBuilder, CommandExecutor};
4+
use postgresql_embedded::PostgreSQL;
5+
use std::fs;
6+
use tempfile::NamedTempFile;
7+
use test_log::test;
8+
9+
#[test(tokio::test)]
10+
async fn dump_command() -> anyhow::Result<()> {
11+
let mut postgresql = PostgreSQL::default();
12+
13+
postgresql.setup().await?;
14+
postgresql.start().await?;
15+
let settings = postgresql.settings();
16+
17+
let database_name = "test";
18+
postgresql.create_database(database_name).await?;
19+
20+
let mut psql = PsqlBuilder::from(settings)
21+
.command("CREATE TABLE person42 (id INTEGER, name VARCHAR(20))")
22+
.dbname(database_name)
23+
.no_psqlrc()
24+
.no_align()
25+
.tuples_only()
26+
.build();
27+
let (_stdout, _stderr) = psql.execute()?;
28+
29+
let temp_file = NamedTempFile::new()?;
30+
let file = temp_file.as_ref();
31+
let mut pgdump = PgDumpBuilder::from(settings)
32+
.dbname(database_name)
33+
.schema_only()
34+
.file(file.to_string_lossy().to_string())
35+
.build();
36+
let (_stdout, _stderr) = pgdump.execute()?;
37+
38+
let contents = fs::read_to_string(file)?;
39+
assert!(contents.contains("person42"));
40+
41+
Ok(())
42+
}

0 commit comments

Comments
 (0)