Skip to content

Commit

Permalink
tests: use integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timvw committed Mar 26, 2024
1 parent 7ef6fdf commit d9636d6
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 75 deletions.
75 changes: 0 additions & 75 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,78 +48,3 @@ async fn main() -> Result<()> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
use assert_cmd::cargo::CargoError;
use assert_cmd::prelude::*;
use datafusion::common::DataFusionError;
use predicates::prelude::*;
use std::env;
use std::process::Command;

fn map_cargo_to_datafusion_error(e: CargoError) -> DataFusionError {
DataFusionError::External(Box::new(e))
}

fn get_qv_cmd() -> Result<Command> {
Command::cargo_bin(env!("CARGO_PKG_NAME")).map_err(map_cargo_to_datafusion_error)
}

#[tokio::test]
async fn run_without_file_exits_with_usage() -> Result<()> {
let mut cmd = get_qv_cmd()?;
cmd.assert()
.failure()
.stderr(predicate::str::contains("Usage: qv <PATH>"));
Ok(())
}

#[tokio::test]
async fn run_with_local_avro_file() -> Result<()> {
let mut cmd = get_qv_cmd()?;
let cmd = cmd.arg(get_qv_testing_path("data/avro/alltypes_plain.avro"));
cmd.assert().success()
.stdout(predicate::str::contains("| id | bool_col | tinyint_col | smallint_col | int_col | bigint_col | float_col | double_col | date_string_col | string_col | timestamp_col |"))
.stdout(predicate::str::contains("| 4 | true | 0 | 0 | 0 | 0 | 0.0 | 0.0 | 30332f30312f3039 | 30 | 2009-03-01T00:00:00 |"));
Ok(())
}

fn get_qv_testing_path(rel_data_path: &str) -> String {
let testing_path = env::var("QV_TESTING_PATH").unwrap_or_else(|_| "./testing".to_string());
format!("{}/{}", testing_path, rel_data_path)
}

#[tokio::test]
async fn run_with_local_parquet_file() -> Result<()> {
let mut cmd = get_qv_cmd()?;
let cmd = cmd.arg(get_qv_testing_path(
"data/parquet/generated_simple_numerics/blogs.parquet",
));
cmd.assert()
.success()
.stdout(predicate::str::contains(
r#"| reply | blog_id |"#,
))
.stdout(predicate::str::contains(
r#"| {reply_id: 332770973, next_id: } | -1473106667809783919 |"#,
));
Ok(())
}

#[tokio::test]
async fn run_with_local_parquet_files_in_folder() -> Result<()> {
let mut cmd = get_qv_cmd()?;
let cmd = cmd.arg(get_qv_testing_path("data/iceberg/db/COVID-19_NYT/data"));
cmd.assert()
.success()
.stdout(predicate::str::contains(
r#"| date | county | state | fips | cases | deaths |"#,
))
.stdout(predicate::str::contains(
r#"| 2020-05-19 | Lawrence | Illinois | 17101 | 4 | 0 |"#,
));
Ok(())
}
}
70 changes: 70 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use assert_cmd::cargo::CargoError;
use assert_cmd::prelude::*;
use datafusion::common::DataFusionError;
use predicates::prelude::*;
use std::env;
use std::process::Command;

fn map_cargo_to_datafusion_error(e: CargoError) -> DataFusionError {
DataFusionError::External(Box::new(e))
}

fn get_qv_cmd() -> datafusion::common::Result<Command> {
Command::cargo_bin(env!("CARGO_PKG_NAME")).map_err(map_cargo_to_datafusion_error)
}

#[tokio::test]
async fn run_without_file_exits_with_usage() -> datafusion::common::Result<()> {
let mut cmd = get_qv_cmd()?;
cmd.assert()
.failure()
.stderr(predicate::str::contains("Usage: qv <PATH>"));
Ok(())
}

#[tokio::test]
async fn run_with_local_avro_file() -> datafusion::common::Result<()> {
let mut cmd = get_qv_cmd()?;
let cmd = cmd.arg(get_qv_testing_path("data/avro/alltypes_plain.avro"));
cmd.assert().success()
.stdout(predicate::str::contains("| id | bool_col | tinyint_col | smallint_col | int_col | bigint_col | float_col | double_col | date_string_col | string_col | timestamp_col |"))
.stdout(predicate::str::contains("| 4 | true | 0 | 0 | 0 | 0 | 0.0 | 0.0 | 30332f30312f3039 | 30 | 2009-03-01T00:00:00 |"));
Ok(())
}

fn get_qv_testing_path(rel_data_path: &str) -> String {
let testing_path = env::var("QV_TESTING_PATH").unwrap_or_else(|_| "./testing".to_string());
format!("{}/{}", testing_path, rel_data_path)
}

#[tokio::test]
async fn run_with_local_parquet_file() -> datafusion::common::Result<()> {
let mut cmd = get_qv_cmd()?;
let cmd = cmd.arg(get_qv_testing_path(
"data/parquet/generated_simple_numerics/blogs.parquet",
));
cmd.assert()
.success()
.stdout(predicate::str::contains(
r#"| reply | blog_id |"#,
))
.stdout(predicate::str::contains(
r#"| {reply_id: 332770973, next_id: } | -1473106667809783919 |"#,
));
Ok(())
}

#[tokio::test]
async fn run_with_local_parquet_files_in_folder() -> datafusion::common::Result<()> {
let mut cmd = get_qv_cmd()?;
let cmd = cmd.arg(get_qv_testing_path("data/iceberg/db/COVID-19_NYT/data"));
cmd.assert()
.success()
.stdout(predicate::str::contains(
r#"| date | county | state | fips | cases | deaths |"#,
))
.stdout(predicate::str::contains(
r#"| 2020-05-19 | Lawrence | Illinois | 17101 | 4 | 0 |"#,
));
Ok(())
}

0 comments on commit d9636d6

Please sign in to comment.