diff options
author | Bryan Newbold <bnewbold@archive.org> | 2020-08-25 14:10:44 -0700 |
---|---|---|
committer | Bryan Newbold <bnewbold@archive.org> | 2020-08-25 14:10:44 -0700 |
commit | d8d10a292a0d6bd0134fcfe785718bb8f48dd085 (patch) | |
tree | 9df0ff2dc7127d88c91666021569896847ede21a /tests/common | |
parent | c49b85ffa31016be21f03e484a263c36932fefe0 (diff) | |
download | es-public-proxy-d8d10a292a0d6bd0134fcfe785718bb8f48dd085.tar.gz es-public-proxy-d8d10a292a0d6bd0134fcfe785718bb8f48dd085.zip |
tests: proper URIs; filter request bodies
Diffstat (limited to 'tests/common')
-rw-r--r-- | tests/common/mod.rs | 23 |
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") +} |