aboutsummaryrefslogtreecommitdiffstats
path: root/tests/serve_request.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/serve_request.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/serve_request.rs b/tests/serve_request.rs
new file mode 100644
index 0000000..31b9b75
--- /dev/null
+++ b/tests/serve_request.rs
@@ -0,0 +1,44 @@
+mod fixtures;
+use fixtures::*;
+
+#[rstest]
+fn serves_requests_with_no_options(tmpdir: TempDir) -> Result<(), Error> {
+ let mut child = Command::cargo_bin("miniserve")?
+ .arg(tmpdir.path())
+ .stdout(Stdio::null())
+ .spawn()?;
+
+ sleep(Duration::from_secs(1));
+
+ let body = reqwest::get("http://localhost:8080")?.error_for_status()?;
+ let parsed = Document::from_read(body)?;
+ for &file in FILES {
+ assert!(parsed.find(Text).any(|x| x.text() == file));
+ }
+
+ child.kill()?;
+
+ Ok(())
+}
+
+#[rstest]
+fn serves_requests_with_non_default_port(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::get(format!("http://localhost:{}", port).as_str())?.error_for_status()?;
+ let parsed = Document::from_read(body)?;
+ for &file in FILES {
+ assert!(parsed.find(Text).any(|x| x.text() == file));
+ }
+
+ child.kill()?;
+
+ Ok(())
+}