diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 53026ce3..2f4a615a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -20,6 +20,7 @@ async-trait = "0.1.64" bollard = "0.14.0" clap = { version = "4.1.1", features = ["derive"] } colorful = "0.2.2" +duct = "0.13.6" elf = "0.7.2" env_logger = "0.10.0" flate2 = "1.0.25" diff --git a/cli/src/commands/test.rs b/cli/src/commands/test.rs index 3fd7890f..6763ab23 100644 --- a/cli/src/commands/test.rs +++ b/cli/src/commands/test.rs @@ -1,14 +1,13 @@ use std::{ - ffi::OsStr, fs::File, io::{BufWriter, Cursor, Read, Write}, - os::unix::process::CommandExt, path::{Path, PathBuf}, - process::Command, + process::{Command, Stdio}, }; use anyhow::{bail, Context}; use clap::Args; +use duct::cmd; use flate2::bufread::GzDecoder; use serde::Deserialize; use tar::{Entry, EntryType}; @@ -109,9 +108,7 @@ async fn extract_sql_and_expected_files( let path = entry.path()?; if check_parent("sql", &path) { - dbg!(&path); let path_written = read_entry(tempdir, &mut entry)?; - dbg!(&path_written); sql_files.push(path_written); } else if check_parent("expected", &path) { let path_written = read_entry(tempdir, &mut entry)?; @@ -166,30 +163,24 @@ impl SubCommand for TestCommand { bail!("Found no matching SQL file for {:?}", expected_file); }; - run_psql(&sql_path, &self.connstring)?; - break; + let obtained = run_psql(&sql_path, &self.connstring)?; + let expected = std::fs::read_to_string(expected_file)?; } - // Run psql (see regress.py) - Ok(()) } } fn run_psql(script_path: &Path, connstring: &str) -> Result { - let child = Command::new("psql") - .args(["--echo-errors", "--echo-all", "--quiet", "-f"]) - .arg(script_path) - .arg(connstring) - .spawn()?; - - let output = child.wait_with_output()?; - let _ = dbg!(String::from_utf8(output.stderr)); + let output = cmd!("psql", "--echo-errors", "--echo-all", "--quiet", "-f", script_path, connstring) + .unchecked() + .stderr_to_stdout() + .read()?; let mut file = File::create("/home/vrmiguel/trunk-test.out")?; - file.write_all(&output.stdout)?; + file.write_all(output.as_bytes())?; - String::from_utf8(output.stdout).map_err(Into::into) + Ok(output) } #[derive(Debug, PartialEq)]