From 796780cd12a9eb024360f71342f2d5d05115fb54 Mon Sep 17 00:00:00 2001 From: Tpt Date: Fri, 25 Nov 2022 14:08:08 +0100 Subject: [PATCH] Attempt to make CLI test pass --- Cargo.lock | 13 +++++++++++++ server/Cargo.toml | 1 + server/src/main.rs | 29 ++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a362d500..7ffb70aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -442,6 +442,18 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "escargot" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5584ba17d7ab26a8a7284f13e5bd196294dd2f2d79773cff29b9e9edef601a6" +dependencies = [ + "log", + "once_cell", + "serde", + "serde_json", +] + [[package]] name = "fastrand" version = "1.8.0" @@ -936,6 +948,7 @@ dependencies = [ "assert_cmd", "assert_fs", "clap 4.0.18", + "escargot", "flate2", "oxhttp", "oxigraph", diff --git a/server/Cargo.toml b/server/Cargo.toml index dc42169f..bfcd54ba 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -26,4 +26,5 @@ rayon-core = "1" [dev-dependencies] assert_cmd = "2" assert_fs = "1" +escargot = "0.5" predicates = "2" diff --git a/server/src/main.rs b/server/src/main.rs index 3e5d4455..326d46c8 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,4 +1,4 @@ -use anyhow::anyhow; +use anyhow::{anyhow, bail}; use clap::{Parser, Subcommand}; use flate2::read::MultiGzDecoder; use oxhttp::model::{Body, HeaderName, HeaderValue, Request, Response, Status}; @@ -160,10 +160,10 @@ fn bulk_load(loader: BulkLoader, reader: impl Read, file: &Path) -> anyhow::Resu loader.load_graph(reader, format, GraphNameRef::DefaultGraph, None)?; Ok(()) } else { - Err(anyhow!( + bail!( "Not able to guess the file format from the extension {}", extension - )) + ) } } @@ -1090,14 +1090,25 @@ impl Write for ReadForWriteWriter { #[cfg(test)] mod tests { use super::*; + use anyhow::Result; use assert_cmd::Command; use assert_fs::prelude::*; use oxhttp::model::Method; use predicates::prelude::*; + fn cli_command() -> Result { + Ok(Command::from_std( + escargot::CargoBuild::new() + .bin(env!("CARGO_PKG_NAME")) + .manifest_path(format!("{}/Cargo.toml", env!("CARGO_MANIFEST_DIR"))) + .run()? + .command(), + )) + } + #[test] - fn cli_help() -> Result<(), Box> { - Command::cargo_bin("oxigraph_server")? + fn cli_help() -> Result<()> { + cli_command()? .assert() .failure() .stdout("") @@ -1106,10 +1117,10 @@ mod tests { } #[test] - fn cli_load_graph() -> Result<(), Box> { + fn cli_load_graph() -> Result<()> { let file = assert_fs::NamedTempFile::new("sample.nt")?; file.write_str(" .")?; - Command::cargo_bin("oxigraph_server")? + cli_command()? .arg("load") .arg("-f") .arg(file.path()) @@ -1121,10 +1132,10 @@ mod tests { } #[test] - fn cli_load_dataset() -> Result<(), Box> { + fn cli_load_dataset() -> Result<()> { let file = assert_fs::NamedTempFile::new("sample.nq")?; file.write_str(" .")?; - Command::cargo_bin("oxigraph_server")? + cli_command()? .arg("load") .arg("-f") .arg(file.path())