From e71703ad90642196cdbe2210bee382e19a1ad258 Mon Sep 17 00:00:00 2001 From: Gabriela Moldovan Date: Mon, 14 Aug 2023 11:02:25 +0100 Subject: [PATCH] tor-dirclient: Move request building to a test helper function. --- crates/tor-dirclient/src/util.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/crates/tor-dirclient/src/util.rs b/crates/tor-dirclient/src/util.rs index bd69dc60c..69c9d3927 100644 --- a/crates/tor-dirclient/src/util.rs +++ b/crates/tor-dirclient/src/util.rs @@ -38,20 +38,22 @@ mod test { //! use super::*; + fn build_request(body: B, headers: &[(&str, &str)]) -> http::Request { + 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] fn format() { - let req = http::Request::builder() - .method("GET") - .uri("/index.html") - .body(()) - .unwrap(); + let req = build_request((), &[]); assert_eq!(encode_request(&req), "GET /index.html HTTP/1.0\r\n\r\n"); - let req = http::Request::builder() - .method("GET") - .uri("/index.html") - .header("X-Marsupial", "Opossum") - .body(()) - .unwrap(); + + let req = build_request((), &[("X-Marsupial", "Opossum")]); assert_eq!( encode_request(&req), "GET /index.html HTTP/1.0\r\nx-marsupial: Opossum\r\n\r\n"