2022-06-12 03:43:50 +03:00
|
|
|
mod fixtures;
|
|
|
|
mod utils;
|
|
|
|
|
2022-06-19 09:23:10 +03:00
|
|
|
use assert_cmd::prelude::*;
|
|
|
|
use assert_fs::fixture::TempDir;
|
|
|
|
use fixtures::{port, server, tmpdir, wait_for_port, Error, TestServer};
|
2022-06-12 03:43:50 +03:00
|
|
|
use rstest::rstest;
|
2022-06-19 09:23:10 +03:00
|
|
|
use std::process::{Command, Stdio};
|
2022-06-12 03:43:50 +03:00
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn path_prefix_index(#[with(&["--path-prefix", "xyz"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = reqwest::blocking::get(format!("{}{}", server.url(), "xyz"))?;
|
|
|
|
assert_index_resp!(resp);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn path_prefix_file(#[with(&["--path-prefix", "xyz"])] server: TestServer) -> Result<(), Error> {
|
|
|
|
let resp = reqwest::blocking::get(format!("{}{}/index.html", server.url(), "xyz"))?;
|
|
|
|
assert_eq!(resp.status(), 200);
|
|
|
|
assert_eq!(resp.text()?, "This is index.html");
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
fn path_prefix_propfind(
|
|
|
|
#[with(&["--path-prefix", "xyz"])] server: TestServer,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let resp = fetch!(b"PROPFIND", format!("{}{}", server.url(), "xyz")).send()?;
|
|
|
|
let text = resp.text()?;
|
|
|
|
assert!(text.contains("<D:href>/xyz/</D:href>"));
|
|
|
|
Ok(())
|
|
|
|
}
|
2022-06-19 09:23:10 +03:00
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
#[case("index.html")]
|
|
|
|
fn serve_single_file(tmpdir: TempDir, port: u16, #[case] file: &str) -> Result<(), Error> {
|
|
|
|
let mut child = Command::cargo_bin("duf")?
|
|
|
|
.env("RUST_LOG", "false")
|
|
|
|
.arg(tmpdir.path().join(file))
|
|
|
|
.arg("-p")
|
|
|
|
.arg(port.to_string())
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()?;
|
|
|
|
|
|
|
|
wait_for_port(port);
|
|
|
|
|
|
|
|
let resp = reqwest::blocking::get(format!("http://localhost:{}/index.html", port))?;
|
|
|
|
assert_eq!(resp.text()?, "This is index.html");
|
|
|
|
|
|
|
|
child.kill()?;
|
|
|
|
Ok(())
|
|
|
|
}
|