2022-07-08 14:30:05 +03:00
|
|
|
//! Run file server with different args
|
|
|
|
|
|
|
|
mod fixtures;
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
use assert_cmd::prelude::*;
|
|
|
|
use assert_fs::fixture::TempDir;
|
|
|
|
use fixtures::{port, tmpdir, wait_for_port, Error};
|
|
|
|
use rstest::rstest;
|
|
|
|
use std::process::{Command, Stdio};
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
#[case("index.html")]
|
|
|
|
fn single_file(tmpdir: TempDir, port: u16, #[case] file: &str) -> Result<(), Error> {
|
|
|
|
let mut child = Command::cargo_bin("dufs")?
|
|
|
|
.arg(tmpdir.path().join(file))
|
|
|
|
.arg("-p")
|
|
|
|
.arg(port.to_string())
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()?;
|
|
|
|
|
|
|
|
wait_for_port(port);
|
|
|
|
|
2023-02-20 06:05:53 +03:00
|
|
|
let resp = reqwest::blocking::get(format!("http://localhost:{port}"))?;
|
2022-07-08 14:30:05 +03:00
|
|
|
assert_eq!(resp.text()?, "This is index.html");
|
2023-02-20 06:05:53 +03:00
|
|
|
let resp = reqwest::blocking::get(format!("http://localhost:{port}/"))?;
|
2022-07-08 14:30:05 +03:00
|
|
|
assert_eq!(resp.text()?, "This is index.html");
|
2023-02-20 06:05:53 +03:00
|
|
|
let resp = reqwest::blocking::get(format!("http://localhost:{port}/index.html"))?;
|
2022-07-08 14:30:05 +03:00
|
|
|
assert_eq!(resp.text()?, "This is index.html");
|
|
|
|
|
|
|
|
child.kill()?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rstest]
|
|
|
|
#[case("index.html")]
|
|
|
|
fn path_prefix_single_file(tmpdir: TempDir, port: u16, #[case] file: &str) -> Result<(), Error> {
|
|
|
|
let mut child = Command::cargo_bin("dufs")?
|
|
|
|
.arg(tmpdir.path().join(file))
|
|
|
|
.arg("-p")
|
|
|
|
.arg(port.to_string())
|
|
|
|
.arg("--path-prefix")
|
|
|
|
.arg("xyz")
|
|
|
|
.stdout(Stdio::piped())
|
|
|
|
.spawn()?;
|
|
|
|
|
|
|
|
wait_for_port(port);
|
|
|
|
|
2023-02-20 06:05:53 +03:00
|
|
|
let resp = reqwest::blocking::get(format!("http://localhost:{port}/xyz"))?;
|
2022-07-08 14:30:05 +03:00
|
|
|
assert_eq!(resp.text()?, "This is index.html");
|
2023-02-20 06:05:53 +03:00
|
|
|
let resp = reqwest::blocking::get(format!("http://localhost:{port}/xyz/"))?;
|
2022-07-08 14:30:05 +03:00
|
|
|
assert_eq!(resp.text()?, "This is index.html");
|
2023-02-20 06:05:53 +03:00
|
|
|
let resp = reqwest::blocking::get(format!("http://localhost:{port}/xyz/index.html"))?;
|
2022-07-08 14:30:05 +03:00
|
|
|
assert_eq!(resp.text()?, "This is index.html");
|
2023-02-20 06:05:53 +03:00
|
|
|
let resp = reqwest::blocking::get(format!("http://localhost:{port}"))?;
|
2024-02-07 11:27:22 +03:00
|
|
|
assert_eq!(resp.status(), 400);
|
2022-07-08 14:30:05 +03:00
|
|
|
|
|
|
|
child.kill()?;
|
|
|
|
Ok(())
|
|
|
|
}
|