aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/archive.rs41
-rw-r--r--tests/cli.rs28
-rw-r--r--tests/fixtures/mod.rs3
-rw-r--r--tests/serve_request.rs11
4 files changed, 80 insertions, 3 deletions
diff --git a/tests/archive.rs b/tests/archive.rs
index c170bc3..6a7f8bf 100644
--- a/tests/archive.rs
+++ b/tests/archive.rs
@@ -51,3 +51,44 @@ fn archives_are_disabled(tmpdir: TempDir, port: u16) -> Result<(), Error> {
Ok(())
}
+
+#[rstest]
+fn test_tar_archives(tmpdir: TempDir, port: u16) -> Result<(), Error> {
+ let mut child = Command::cargo_bin("miniserve")?
+ .arg(tmpdir.path())
+ .arg("-p")
+ .arg(port.to_string())
+ .arg("-g")
+ .stdout(Stdio::null())
+ .spawn()?;
+
+ sleep(Duration::from_secs(1));
+
+ // Ensure the links to the tar archive exists and tar not exists
+ let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())?
+ .error_for_status()?;
+ let parsed = Document::from_read(body)?;
+ assert!(parsed.find(Text).any(|x| x.text() == "Download .tar.gz"));
+ assert!(parsed.find(Text).all(|x| x.text() != "Download .tar"));
+
+ // Try to download, only tar_gz should works
+ assert_eq!(
+ reqwest::blocking::get(format!("http://localhost:{}/?download=tar_gz", port).as_str())?
+ .status(),
+ StatusCode::OK
+ );
+ assert_eq!(
+ reqwest::blocking::get(format!("http://localhost:{}/?download=tar", port).as_str())?
+ .status(),
+ StatusCode::FORBIDDEN
+ );
+ assert_eq!(
+ reqwest::blocking::get(format!("http://localhost:{}/?download=zip", port).as_str())?
+ .status(),
+ StatusCode::FORBIDDEN
+ );
+
+ child.kill()?;
+
+ Ok(())
+}
diff --git a/tests/cli.rs b/tests/cli.rs
index e09473d..f88b284 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -3,7 +3,7 @@ mod fixtures;
use assert_cmd::prelude::*;
use fixtures::Error;
use std::process::Command;
-use structopt::clap::{crate_name, crate_version};
+use structopt::clap::{crate_name, crate_version, Shell};
#[test]
/// Show help and exit.
@@ -27,3 +27,29 @@ fn version_shows() -> Result<(), Error> {
Ok(())
}
+
+#[test]
+/// Print completions and exit.
+fn print_completions() -> Result<(), Error> {
+ for shell in &Shell::variants() {
+ Command::cargo_bin("miniserve")?
+ .arg("--print-completions")
+ .arg(&shell)
+ .assert()
+ .success();
+ }
+
+ Ok(())
+}
+
+#[test]
+/// Print completions rejects invalid shells.
+fn print_completions_invalid_shell() -> Result<(), Error> {
+ Command::cargo_bin("miniserve")?
+ .arg("--print-completions")
+ .arg("fakeshell")
+ .assert()
+ .failure();
+
+ Ok(())
+}
diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs
index 7efbe5e..1cf6c59 100644
--- a/tests/fixtures/mod.rs
+++ b/tests/fixtures/mod.rs
@@ -16,6 +16,9 @@ pub static FILES: &[&str] = &[
"test \" \' & < >.csv",
"😀.data",
"⎙.mp4",
+ "#[]{}()@!$&'`+,;= %20.test",
+ #[cfg(unix)]
+ ":?#[]{}<>()@!$&'`|*+,;= %20.test",
];
/// Hidden files for testing purpose
diff --git a/tests/serve_request.rs b/tests/serve_request.rs
index 1e92339..e259b9e 100644
--- a/tests/serve_request.rs
+++ b/tests/serve_request.rs
@@ -55,6 +55,12 @@ fn serves_requests_with_non_default_port(tmpdir: TempDir, port: u16) -> Result<(
for &file in FILES {
let f = parsed.find(|x: &Node| x.text() == file).next().unwrap();
+ reqwest::blocking::get(format!(
+ "http://localhost:{}/{}",
+ port,
+ f.attr("href").unwrap()
+ ))?
+ .error_for_status()?;
assert_eq!(
format!("/{}", file),
percent_encoding::percent_decode_str(f.attr("href").unwrap()).decode_utf8_lossy(),
@@ -259,17 +265,18 @@ fn serves_requests_custom_index_notice(tmpdir: TempDir, port: u16) -> Result<(),
.arg(port.to_string())
.arg(tmpdir.path())
.stdout(Stdio::piped())
+ .stderr(Stdio::piped())
.spawn()?;
sleep(Duration::from_secs(1));
child.kill()?;
let output = child.wait_with_output().expect("Failed to read stdout");
- let all_text = String::from_utf8(output.stdout);
+ let all_text = String::from_utf8(output.stderr);
assert!(all_text
.unwrap()
- .contains("The provided index file could not be found"));
+ .contains("The file 'not.html' provided for option --index could not be found."));
Ok(())
}