tor-dirclient: Move request building to a test helper function.
This commit is contained in:
parent
636a18bd7d
commit
e71703ad90
|
@ -38,20 +38,22 @@ mod test {
|
||||||
//! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
|
//! <!-- @@ end test lint list maintained by maint/add_warning @@ -->
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
fn build_request<B: StringBody>(body: B, headers: &[(&str, &str)]) -> http::Request<B> {
|
||||||
|
let mut builder = http::Request::builder().method("GET").uri("/index.html");
|
||||||
|
|
||||||
|
for (name, value) in headers {
|
||||||
|
builder = builder.header(*name, *value);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.body(body).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn format() {
|
fn format() {
|
||||||
let req = http::Request::builder()
|
let req = build_request((), &[]);
|
||||||
.method("GET")
|
|
||||||
.uri("/index.html")
|
|
||||||
.body(())
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(encode_request(&req), "GET /index.html HTTP/1.0\r\n\r\n");
|
assert_eq!(encode_request(&req), "GET /index.html HTTP/1.0\r\n\r\n");
|
||||||
let req = http::Request::builder()
|
|
||||||
.method("GET")
|
let req = build_request((), &[("X-Marsupial", "Opossum")]);
|
||||||
.uri("/index.html")
|
|
||||||
.header("X-Marsupial", "Opossum")
|
|
||||||
.body(())
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
encode_request(&req),
|
encode_request(&req),
|
||||||
"GET /index.html HTTP/1.0\r\nx-marsupial: Opossum\r\n\r\n"
|
"GET /index.html HTTP/1.0\r\nx-marsupial: Opossum\r\n\r\n"
|
||||||
|
|
Loading…
Reference in New Issue