From 996ac309ab33aea63dbcd762f2c85e6836d73c5f Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Fri, 10 Jan 2025 16:32:11 +0100 Subject: Remove some unnecessary #[allow(dead_code)] --- tests/fixtures/mod.rs | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'tests/fixtures') diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs index 96b8002..f5231f7 100644 --- a/tests/fixtures/mod.rs +++ b/tests/fixtures/mod.rs @@ -12,7 +12,6 @@ use std::time::{Duration, Instant}; pub type Error = Box; /// File names for testing purpose -#[allow(dead_code)] pub static FILES: &[&str] = &[ "test.txt", "test.html", @@ -31,25 +30,20 @@ pub static FILES: &[&str] = &[ ]; /// Hidden files for testing purpose -#[allow(dead_code)] pub static HIDDEN_FILES: &[&str] = &[".hidden_file1", ".hidden_file2"]; /// Directory names for testing purpose -#[allow(dead_code)] pub static DIRECTORIES: &[&str] = &["dira/", "dirb/", "dirc/"]; /// Hidden directories for testing purpose -#[allow(dead_code)] pub static HIDDEN_DIRECTORIES: &[&str] = &[".hidden_dir1/", ".hidden_dir2/"]; /// Name of a deeply nested file -#[allow(dead_code)] pub static DEEPLY_NESTED_FILE: &str = "very/deeply/nested/test.rs"; /// Test fixture which creates a temporary directory with a few files and directories inside. /// The directories also contain files. #[fixture] -#[allow(dead_code)] pub fn tmpdir() -> TempDir { let tmpdir = assert_fs::TempDir::new().expect("Couldn't create a temp dir for tests"); let mut files = FILES.to_vec(); @@ -81,7 +75,6 @@ pub fn tmpdir() -> TempDir { /// Get a free port. #[fixture] -#[allow(dead_code)] pub fn port() -> u16 { free_local_port().expect("Couldn't find a free local port") } @@ -89,7 +82,6 @@ pub fn port() -> u16 { /// Run miniserve as a server; Start with a temporary directory, a free port and some /// optional arguments then wait for a while for the server setup to complete. #[fixture] -#[allow(dead_code)] pub fn server(#[default(&[] as &[&str])] args: I) -> TestServer where I: IntoIterator + Clone, @@ -116,7 +108,6 @@ where /// Same as `server()` but ignore stderr #[fixture] -#[allow(dead_code)] pub fn server_no_stderr(#[default(&[] as &[&str])] args: I) -> TestServer where I: IntoIterator + Clone, @@ -155,7 +146,6 @@ fn wait_for_port(port: u16) { } } -#[allow(dead_code)] pub struct TestServer { port: u16, tmpdir: TempDir, -- cgit v1.2.3 From a4144c9fb39c7a3cc1c15a8caec68b32de938ce7 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Thu, 6 Feb 2025 04:12:21 +0100 Subject: Make symlinks into global fixtures So far, tests had to create their own symlinks which made them less concise. Also, now that we always have symlinks in all tests, side effects of having them won't go undetected. --- tests/fixtures/mod.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'tests/fixtures') diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs index f5231f7..a96a5b7 100644 --- a/tests/fixtures/mod.rs +++ b/tests/fixtures/mod.rs @@ -1,12 +1,13 @@ +use std::process::{Child, Command, Stdio}; +use std::thread::sleep; +use std::time::{Duration, Instant}; + use assert_cmd::prelude::*; use assert_fs::fixture::TempDir; use assert_fs::prelude::*; use port_check::free_local_port; use reqwest::Url; use rstest::fixture; -use std::process::{Child, Command, Stdio}; -use std::thread::sleep; -use std::time::{Duration, Instant}; /// Error type used by tests pub type Error = Box; @@ -41,6 +42,15 @@ pub static HIDDEN_DIRECTORIES: &[&str] = &[".hidden_dir1/", ".hidden_dir2/"]; /// Name of a deeply nested file pub static DEEPLY_NESTED_FILE: &str = "very/deeply/nested/test.rs"; +/// Name of a symlink pointing to a directory +pub static DIRECTORY_SYMLINK: &str = "dir_symlink/"; + +/// Name of a symlink pointing to a file +pub static FILE_SYMLINK: &str = "file_symlink"; + +/// Name of a symlink pointing to a path that doesn't exist +pub static BROKEN_SYMLINK: &str = "broken_symlink"; + /// Test fixture which creates a temporary directory with a few files and directories inside. /// The directories also contain files. #[fixture] @@ -70,6 +80,22 @@ pub fn tmpdir() -> TempDir { .child(DEEPLY_NESTED_FILE) .write_str("File in a deeply nested directory.") .expect("Couldn't write to file"); + + tmpdir + .child(DIRECTORY_SYMLINK.strip_suffix("/").unwrap()) + .symlink_to_dir(DIRECTORIES[0]) + .expect("Couldn't create symlink to dir"); + + tmpdir + .child(FILE_SYMLINK) + .symlink_to_file(FILES[0]) + .expect("Couldn't create symlink to file"); + + tmpdir + .child(BROKEN_SYMLINK) + .symlink_to_file("broken_symlink") + .expect("Couldn't create broken symlink"); + tmpdir } -- cgit v1.2.3 From f0eb61436e62d0d0d755ac8280bf97b4b52d4e0b Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Thu, 6 Feb 2025 04:30:28 +0100 Subject: Get rid of server_no_stderr We'll now always just pipe the contents of the child to the parent. --- tests/fixtures/mod.rs | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'tests/fixtures') diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs index a96a5b7..f95d4f6 100644 --- a/tests/fixtures/mod.rs +++ b/tests/fixtures/mod.rs @@ -121,34 +121,8 @@ where .arg("-p") .arg(port.to_string()) .args(args.clone()) - .stdout(Stdio::null()) - .spawn() - .expect("Couldn't run test binary"); - let is_tls = args - .into_iter() - .any(|x| x.as_ref().to_str().unwrap().contains("tls")); - - wait_for_port(port); - TestServer::new(port, tmpdir, child, is_tls) -} - -/// Same as `server()` but ignore stderr -#[fixture] -pub fn server_no_stderr(#[default(&[] as &[&str])] args: I) -> TestServer -where - I: IntoIterator + Clone, - I::Item: AsRef, -{ - let port = port(); - let tmpdir = tmpdir(); - let child = Command::cargo_bin("miniserve") - .expect("Couldn't find test binary") - .arg(tmpdir.path()) - .arg("-p") - .arg(port.to_string()) - .args(args.clone()) - .stdout(Stdio::null()) - .stderr(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) .spawn() .expect("Couldn't run test binary"); let is_tls = args -- cgit v1.2.3 From e2a6761c38f6d882ebcd7c51c2c539500e2230b8 Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Thu, 6 Feb 2025 06:51:53 +0100 Subject: Strip symlink target dir to make Windows happy Turns out Windows doesn't like forward slashes. --- tests/fixtures/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/fixtures') diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs index f95d4f6..f2869b7 100644 --- a/tests/fixtures/mod.rs +++ b/tests/fixtures/mod.rs @@ -83,7 +83,7 @@ pub fn tmpdir() -> TempDir { tmpdir .child(DIRECTORY_SYMLINK.strip_suffix("/").unwrap()) - .symlink_to_dir(DIRECTORIES[0]) + .symlink_to_dir(DIRECTORIES[0].strip_suffix("/").unwrap()) .expect("Couldn't create symlink to dir"); tmpdir -- cgit v1.2.3