From 0168cfbe7b4ff67c73ce3a70f5f242b2502aba40 Mon Sep 17 00:00:00 2001 From: Matthew Turner Date: Tue, 14 Jan 2025 08:57:55 -0500 Subject: [PATCH] Add tests --- tests/cli_cases/basic.rs | 73 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/tests/cli_cases/basic.rs b/tests/cli_cases/basic.rs index 29c7952..e1a7066 100644 --- a/tests/cli_cases/basic.rs +++ b/tests/cli_cases/basic.rs @@ -18,7 +18,7 @@ //! Tests for the CLI (e.g. run from files) use assert_cmd::Command; -use std::path::PathBuf; +use std::{io::Read, path::PathBuf}; use super::{assert_output_contains, contains_str, sql_in_file}; @@ -410,3 +410,74 @@ fn test_more_than_one_command_with_output() { let expected = "Error: Output can only be saved for a single file or command"; assert.stderr(contains_str(expected)); } + +#[test] +fn test_output_csv() { + let sql = "SELECT 1".to_string(); + Command::cargo_bin("dft") + .unwrap() + .arg("-c") + .arg(sql.clone()) + .arg("-o") + .arg("test.csv") + .assert() + .success(); + + let mut file = std::fs::File::open("test.csv").unwrap(); + let mut buffer = String::new(); + file.read_to_string(&mut buffer).unwrap(); + + let expected = "Int64(1)\n1\n"; + assert_eq!(buffer, expected); +} + +#[test] +fn test_output_json() { + let sql = "SELECT 1".to_string(); + Command::cargo_bin("dft") + .unwrap() + .arg("-c") + .arg(sql.clone()) + .arg("-o") + .arg("test.json") + .assert() + .success(); + + let mut file = std::fs::File::open("test.json").unwrap(); + let mut buffer = String::new(); + file.read_to_string(&mut buffer).unwrap(); + + let expected = "{\"Int64(1)\":1}\n"; + assert_eq!(buffer, expected); +} + +#[test] +fn test_output_parquet() { + let sql = "SELECT 1".to_string(); + Command::cargo_bin("dft") + .unwrap() + .arg("-c") + .arg(sql.clone()) + .arg("-o") + .arg("test.parquet") + .assert() + .success(); + + let read_sql = "SELECT * FROM 'test.parquet'"; + + let assert = Command::cargo_bin("dft") + .unwrap() + .arg("-c") + .arg(read_sql) + .assert() + .success(); + + let expected = r#" ++----------+ +| Int64(1) | ++----------+ +| 1 | ++----------+"#; + + assert.stdout(contains_str(expected)); +}