Attempt to make CLI test pass

pull/299/head
Tpt 2 years ago committed by Thomas Tanon
parent c9762fc280
commit 796780cd12
  1. 13
      Cargo.lock
  2. 1
      server/Cargo.toml
  3. 29
      server/src/main.rs

13
Cargo.lock generated

@ -442,6 +442,18 @@ version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" 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]] [[package]]
name = "fastrand" name = "fastrand"
version = "1.8.0" version = "1.8.0"
@ -936,6 +948,7 @@ dependencies = [
"assert_cmd", "assert_cmd",
"assert_fs", "assert_fs",
"clap 4.0.18", "clap 4.0.18",
"escargot",
"flate2", "flate2",
"oxhttp", "oxhttp",
"oxigraph", "oxigraph",

@ -26,4 +26,5 @@ rayon-core = "1"
[dev-dependencies] [dev-dependencies]
assert_cmd = "2" assert_cmd = "2"
assert_fs = "1" assert_fs = "1"
escargot = "0.5"
predicates = "2" predicates = "2"

@ -1,4 +1,4 @@
use anyhow::anyhow; use anyhow::{anyhow, bail};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use flate2::read::MultiGzDecoder; use flate2::read::MultiGzDecoder;
use oxhttp::model::{Body, HeaderName, HeaderValue, Request, Response, Status}; 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)?; loader.load_graph(reader, format, GraphNameRef::DefaultGraph, None)?;
Ok(()) Ok(())
} else { } else {
Err(anyhow!( bail!(
"Not able to guess the file format from the extension {}", "Not able to guess the file format from the extension {}",
extension extension
)) )
} }
} }
@ -1090,14 +1090,25 @@ impl Write for ReadForWriteWriter {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use anyhow::Result;
use assert_cmd::Command; use assert_cmd::Command;
use assert_fs::prelude::*; use assert_fs::prelude::*;
use oxhttp::model::Method; use oxhttp::model::Method;
use predicates::prelude::*; use predicates::prelude::*;
fn cli_command() -> Result<Command> {
Ok(Command::from_std(
escargot::CargoBuild::new()
.bin(env!("CARGO_PKG_NAME"))
.manifest_path(format!("{}/Cargo.toml", env!("CARGO_MANIFEST_DIR")))
.run()?
.command(),
))
}
#[test] #[test]
fn cli_help() -> Result<(), Box<dyn std::error::Error>> { fn cli_help() -> Result<()> {
Command::cargo_bin("oxigraph_server")? cli_command()?
.assert() .assert()
.failure() .failure()
.stdout("") .stdout("")
@ -1106,10 +1117,10 @@ mod tests {
} }
#[test] #[test]
fn cli_load_graph() -> Result<(), Box<dyn std::error::Error>> { fn cli_load_graph() -> Result<()> {
let file = assert_fs::NamedTempFile::new("sample.nt")?; let file = assert_fs::NamedTempFile::new("sample.nt")?;
file.write_str("<http://example.com/s> <http://example.com/p> <http://example.com/o> .")?; file.write_str("<http://example.com/s> <http://example.com/p> <http://example.com/o> .")?;
Command::cargo_bin("oxigraph_server")? cli_command()?
.arg("load") .arg("load")
.arg("-f") .arg("-f")
.arg(file.path()) .arg(file.path())
@ -1121,10 +1132,10 @@ mod tests {
} }
#[test] #[test]
fn cli_load_dataset() -> Result<(), Box<dyn std::error::Error>> { fn cli_load_dataset() -> Result<()> {
let file = assert_fs::NamedTempFile::new("sample.nq")?; let file = assert_fs::NamedTempFile::new("sample.nq")?;
file.write_str("<http://example.com/s> <http://example.com/p> <http://example.com/o> .")?; file.write_str("<http://example.com/s> <http://example.com/p> <http://example.com/o> .")?;
Command::cargo_bin("oxigraph_server")? cli_command()?
.arg("load") .arg("load")
.arg("-f") .arg("-f")
.arg(file.path()) .arg(file.path())

Loading…
Cancel
Save