aboutsummaryrefslogtreecommitdiffstats
path: root/tests/header.rs
diff options
context:
space:
mode:
authorAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2021-04-24 04:28:55 +0000
committerAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2021-08-26 11:21:47 +0000
commitdfd0ecf931b68ea373be1e4e785421d48ca6fed5 (patch)
tree115986299dcdeccc0bf2fac00da32dc64759ec1f /tests/header.rs
parentUpgrade deps (diff)
downloadminiserve-dfd0ecf931b68ea373be1e4e785421d48ca6fed5.tar.gz
miniserve-dfd0ecf931b68ea373be1e4e785421d48ca6fed5.zip
tests: Refactor!
Remove duplicate code responsible for the initial setup and teardown of the test binary. This introduces `TestServer` as a resource manager for a running miniserve binary, which can be created with the fixtures `server()` and `server_no_stderr()` It also provides convenience function for handling server url.
Diffstat (limited to 'tests/header.rs')
-rw-r--r--tests/header.rs24
1 files changed, 4 insertions, 20 deletions
diff --git a/tests/header.rs b/tests/header.rs
index e46044c..4ac38b1 100644
--- a/tests/header.rs
+++ b/tests/header.rs
@@ -1,29 +1,15 @@
mod fixtures;
-use assert_cmd::prelude::*;
-use assert_fs::fixture::TempDir;
-use fixtures::{port, tmpdir, Error};
+use fixtures::{server, Error};
use rstest::rstest;
-use std::process::{Command, Stdio};
-use std::thread::sleep;
-use std::time::Duration;
#[rstest(headers,
case(vec!["x-info: 123".to_string()]),
case(vec!["x-info1: 123".to_string(), "x-info2: 345".to_string()])
)]
-fn custom_header_set(tmpdir: TempDir, port: u16, headers: Vec<String>) -> Result<(), Error> {
- let mut child = Command::cargo_bin("miniserve")?
- .arg(tmpdir.path())
- .arg("-p")
- .arg(port.to_string())
- .args(headers.iter().flat_map(|h| vec!["--header", h]))
- .stdout(Stdio::null())
- .spawn()?;
-
- sleep(Duration::from_secs(1));
-
- let resp = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())?;
+fn custom_header_set(headers: Vec<String>) -> Result<(), Error> {
+ let server = server(headers.iter().flat_map(|h| vec!["--header", h]));
+ let resp = reqwest::blocking::get(server.url())?;
for header in headers {
let mut header_split = header.splitn(2, ':');
@@ -32,7 +18,5 @@ fn custom_header_set(tmpdir: TempDir, port: u16, headers: Vec<String>) -> Result
assert_eq!(resp.headers().get(header_name).unwrap(), header_value);
}
- child.kill()?;
-
Ok(())
}