summaryrefslogtreecommitdiffstats
path: root/tests/common
diff options
context:
space:
mode:
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/mod.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index a65fb2e..890dead 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1,20 +1,21 @@
+use hyper::{Request, Body, Method};
use std::path::Path;
use std::io::BufRead;
-pub struct ExampleRequest {
+pub struct ExampleParts {
pub method: String,
pub path_and_query: String,
pub body: Option<String>,
}
-pub fn load_request_by_name(name: &str) -> ExampleRequest {
+pub fn load_parts_by_name(name: &str) -> ExampleParts {
let path = format!("tests/files/{}.txt", name);
let path = Path::new(&path);
- load_request(&path)
+ load_parts(&path)
}
-pub fn load_request(path: &Path) -> ExampleRequest {
+pub fn load_parts(path: &Path) -> ExampleParts {
let file = std::fs::File::open(path).unwrap();
let mut lines = std::io::BufReader::new(file).lines();
@@ -26,9 +27,21 @@ pub fn load_request(path: &Path) -> ExampleRequest {
Some(body.join("\n"))
};
- ExampleRequest {
+ ExampleParts {
method: first_line[0].clone(),
path_and_query: first_line[1].clone(),
body: body,
}
}
+
+pub fn load_request(path: &Path) -> Request<Body> {
+ let parts = load_parts(path);
+ Request::builder()
+ .uri(parts.path_and_query)
+ .method(Method::from_bytes(parts.method.as_bytes()).expect("valid method in example text file"))
+ .body(match parts.body {
+ Some(data) => Body::from(data),
+ None => Body::empty(),
+ })
+ .expect("constructing upstream request")
+}