From a389db173b8b6f38c8330ddecf00023c72c8ee86 Mon Sep 17 00:00:00 2001 From: Andy Freeland Date: Thu, 25 Mar 2021 21:06:08 -0700 Subject: Generate completions with `miniserve --print-completions ` This patch adds a `--print-completions` option to generate shell completion files at runtime. This ensures the completions are always up to date. Fixes #377. --- tests/cli.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tests') 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(()) +} -- cgit v1.2.3 From d1f1ff93c7d667614bf50e877eb1eef7eed9132a Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Sun, 28 Mar 2021 21:44:52 +0200 Subject: Fix tests --- tests/serve_request.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/serve_request.rs b/tests/serve_request.rs index 95449f5..6477bc2 100644 --- a/tests/serve_request.rs +++ b/tests/serve_request.rs @@ -185,17 +185,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(()) } -- cgit v1.2.3 From 58f40d8314821624ab55aa45493cedd407ee0376 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Tue, 6 Apr 2021 20:16:59 +0300 Subject: Test URL encoding for special characters --- tests/fixtures/mod.rs | 3 +++ tests/serve_request.rs | 6 ++++++ 2 files changed, 9 insertions(+) (limited to 'tests') 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 6477bc2..25c5574 100644 --- a/tests/serve_request.rs +++ b/tests/serve_request.rs @@ -49,6 +49,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(), -- cgit v1.2.3 From 2bae301ed8efcf4239849a45b94cdc42e398b905 Mon Sep 17 00:00:00 2001 From: Dean Li Date: Sun, 11 Apr 2021 11:00:16 +0800 Subject: Separate tar archive and tar flags It used to have one flag (-r) to enable both tar archive and tar. Now it has two flags [ -r: for tar, -g: for tar archive]. Related to #451 --- tests/archive.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests') 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(()) +} -- cgit v1.2.3