Skip to content
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

test: add command integration test #50

Merged
merged 2 commits into from
Apr 3, 2024
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
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion postgresql_embedded/src/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use postgresql_commands::initdb::InitDbBuilder;
use postgresql_commands::pg_ctl::Mode::{Start, Stop};
use postgresql_commands::pg_ctl::PgCtlBuilder;
use postgresql_commands::pg_ctl::ShutdownMode::Fast;
use postgresql_commands::psql::PsqlBuilder;
#[cfg(feature = "tokio")]
use postgresql_commands::AsyncCommandExecutor;
use postgresql_commands::CommandBuilder;
Expand All @@ -22,7 +23,6 @@ use std::str::FromStr;
use tracing::{debug, instrument};

use crate::Error::{CreateDatabaseError, DatabaseExistsError, DropDatabaseError};
use postgresql_commands::psql::PsqlBuilder;

#[cfg(feature = "bundled")]
lazy_static::lazy_static! {
Expand Down
42 changes: 42 additions & 0 deletions postgresql_embedded/tests/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use postgresql_commands::pg_dump::PgDumpBuilder;
use postgresql_commands::psql::PsqlBuilder;
use postgresql_commands::{CommandBuilder, CommandExecutor};
use postgresql_embedded::PostgreSQL;
use std::fs;
use tempfile::NamedTempFile;
use test_log::test;

#[test(tokio::test)]
async fn dump_command() -> anyhow::Result<()> {
let mut postgresql = PostgreSQL::default();

postgresql.setup().await?;
postgresql.start().await?;
let settings = postgresql.settings();

let database_name = "test";
postgresql.create_database(database_name).await?;

let mut psql = PsqlBuilder::from(settings)
.command("CREATE TABLE person42 (id INTEGER, name VARCHAR(20))")
.dbname(database_name)
.no_psqlrc()
.no_align()
.tuples_only()
.build();
let (_stdout, _stderr) = psql.execute()?;

let temp_file = NamedTempFile::new()?;
let file = temp_file.as_ref();
let mut pgdump = PgDumpBuilder::from(settings)
.dbname(database_name)
.schema_only()
.file(file.to_string_lossy().to_string())
.build();
let (_stdout, _stderr) = pgdump.execute()?;

let contents = fs::read_to_string(file)?;
assert!(contents.contains("person42"));

Ok(())
}
Loading