aboutsummaryrefslogtreecommitdiffstats
path: root/tests/qrcode.rs
diff options
context:
space:
mode:
authorSven-Hendrik Haase <svenstaro@gmail.com>2021-08-26 23:13:24 +0000
committerGitHub <noreply@github.com>2021-08-26 23:13:24 +0000
commit4ab0756eb007a0263e174d1116132a2b55ef0fe3 (patch)
tree89439bc8e5c772d95996542e992d95f8b96297a4 /tests/qrcode.rs
parentUpgrade deps (diff)
parentnew partial-injection syntax (diff)
downloadminiserve-4ab0756eb007a0263e174d1116132a2b55ef0fe3.tar.gz
miniserve-4ab0756eb007a0263e174d1116132a2b55ef0fe3.zip
Merge pull request #506 from aliemjay/test-refactor
[Refactor] tests: Refactor!
Diffstat (limited to 'tests/qrcode.rs')
-rw-r--r--tests/qrcode.rs59
1 files changed, 8 insertions, 51 deletions
diff --git a/tests/qrcode.rs b/tests/qrcode.rs
index d9a5529..a9c27fe 100644
--- a/tests/qrcode.rs
+++ b/tests/qrcode.rs
@@ -1,74 +1,34 @@
mod fixtures;
-use assert_cmd::prelude::*;
-use assert_fs::fixture::TempDir;
-use fixtures::{port, tmpdir, Error};
+use fixtures::{server, server_no_stderr, Error, TestServer};
use reqwest::StatusCode;
use rstest::rstest;
use select::document::Document;
use select::predicate::Attr;
use std::iter::repeat_with;
-use std::process::{Command, Stdio};
-use std::thread::sleep;
-use std::time::Duration;
#[rstest]
-fn hide_qrcode_element(tmpdir: TempDir, port: u16) -> Result<(), Error> {
- let mut child = Command::cargo_bin("miniserve")?
- .arg(tmpdir.path())
- .arg("-p")
- .arg(port.to_string())
- .stdout(Stdio::null())
- .spawn()?;
-
- sleep(Duration::from_secs(1));
-
- let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())?
- .error_for_status()?;
+fn hide_qrcode_element(server: TestServer) -> Result<(), Error> {
+ let body = reqwest::blocking::get(server.url())?.error_for_status()?;
let parsed = Document::from_read(body)?;
assert!(parsed.find(Attr("id", "qrcode")).next().is_none());
- child.kill()?;
-
Ok(())
}
#[rstest]
-fn show_qrcode_element(tmpdir: TempDir, port: u16) -> Result<(), Error> {
- let mut child = Command::cargo_bin("miniserve")?
- .arg(tmpdir.path())
- .arg("-p")
- .arg(port.to_string())
- .arg("-q")
- .stdout(Stdio::null())
- .spawn()?;
-
- sleep(Duration::from_secs(1));
-
- let body = reqwest::blocking::get(format!("http://localhost:{}", port).as_str())?
- .error_for_status()?;
+fn show_qrcode_element(#[with(&["-q"])] server: TestServer) -> Result<(), Error> {
+ let body = reqwest::blocking::get(server.url())?.error_for_status()?;
let parsed = Document::from_read(body)?;
assert!(parsed.find(Attr("id", "qrcode")).next().is_some());
- child.kill()?;
-
Ok(())
}
#[rstest]
-fn get_svg_qrcode(tmpdir: TempDir, port: u16) -> Result<(), Error> {
- let mut child = Command::cargo_bin("miniserve")?
- .arg(tmpdir.path())
- .arg("-p")
- .arg(port.to_string())
- .stdout(Stdio::null())
- .stderr(Stdio::null())
- .spawn()?;
-
- sleep(Duration::from_secs(1));
-
+fn get_svg_qrcode(#[from(server_no_stderr)] server: TestServer) -> Result<(), Error> {
// Ok
- let resp = reqwest::blocking::get(format!("http://localhost:{}/?qrcode=test", port).as_str())?;
+ let resp = reqwest::blocking::get(server.url().join("/?qrcode=test")?)?;
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(resp.headers()["Content-Type"], "image/svg+xml");
@@ -78,12 +38,9 @@ fn get_svg_qrcode(tmpdir: TempDir, port: u16) -> Result<(), Error> {
// Err
let content: String = repeat_with(|| '0').take(8 * 1024).collect();
- let resp =
- reqwest::blocking::get(format!("http://localhost:{}/?qrcode={}", port, content).as_str())?;
+ let resp = reqwest::blocking::get(server.url().join(&format!("?qrcode={}", content))?)?;
assert_eq!(resp.status(), StatusCode::URI_TOO_LONG);
- child.kill()?;
-
Ok(())
}