aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fixtures/mod.rs
diff options
context:
space:
mode:
authorboastful-squirrel <boastful.squirrel@gmail.com>2019-05-03 05:28:31 +0000
committerboastful-squirrel <boastful.squirrel@gmail.com>2019-05-03 05:28:31 +0000
commit8f1793e02f0dadbab668b51850e14bd160b440d8 (patch)
tree4e125df23c71e092c3f83d0289554df980e0bb2e /tests/fixtures/mod.rs
parentPrint error when parsing query parameters fail (diff)
parentMerge pull request #99 from KSXGitHub/new-clippy (diff)
downloadminiserve-8f1793e02f0dadbab668b51850e14bd160b440d8.tar.gz
miniserve-8f1793e02f0dadbab668b51850e14bd160b440d8.zip
Merge branch 'master' into themed-errors
Diffstat (limited to '')
-rw-r--r--tests/fixtures/mod.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs
new file mode 100644
index 0000000..9cfd2cf
--- /dev/null
+++ b/tests/fixtures/mod.rs
@@ -0,0 +1,32 @@
+use assert_fs::fixture::TempDir;
+use assert_fs::prelude::*;
+use port_check::free_local_port;
+use rstest::fixture;
+
+/// Error type used by tests
+pub type Error = Box<std::error::Error>;
+
+/// File names for testing purpose
+#[allow(dead_code)]
+pub static FILES: &[&str] = &["test.txt", "test.html", "test.mkv"];
+
+/// Test fixture which creates a temporary directory with a few files inside.
+#[fixture]
+#[allow(dead_code)]
+pub fn tmpdir() -> TempDir {
+ let tmpdir = assert_fs::TempDir::new().expect("Couldn't create a temp dir for tests");
+ for &file in FILES {
+ tmpdir
+ .child(file)
+ .write_str("Test Hello Yes")
+ .expect("Couldn't write to file");
+ }
+ tmpdir
+}
+
+/// Get a free port.
+#[fixture]
+#[allow(dead_code)]
+pub fn port() -> u16 {
+ free_local_port().expect("Couldn't find a free local port")
+}