tor-dirclient: Move request building to a test helper function.

This commit is contained in:
Gabriela Moldovan 2023-08-14 11:02:25 +01:00
parent 636a18bd7d
commit e71703ad90
No known key found for this signature in database
GPG Key ID: 3946E0ADE72BAC99
1 changed files with 13 additions and 11 deletions

View File

@ -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"