feat(net): add tracing to matching each criteria for mock request
All checks were successful
Test / build (map[name:nightly]) (push) Successful in 9m28s
Test / build (map[name:stable]) (push) Successful in 10m53s
Release Please / Release-plz (push) Successful in 1m56s

This commit is contained in:
Paul Campbell 2024-12-28 17:48:27 +00:00
parent add2fc93af
commit 9b7a2870ff

View file

@ -32,15 +32,17 @@ struct Plan {
response: reqwest::Response, response: reqwest::Response,
} }
impl Plan { impl Plan {
#[tracing::instrument] #[tracing::instrument(skip(self))]
fn matches(&self, request: &Request) -> bool { fn matches(&self, request: &Request) -> bool {
let url = request.url(); let url = request.url();
let is_match = let is_match =
self.match_request.iter().all(|criteria| match criteria { self.match_request.iter().all(|criteria| match criteria {
MatchRequest::Body(body) => { MatchRequest::Body(body) => {
tracing::trace!(body = ?request.body(), "BODY");
request.body().and_then(reqwest::Body::as_bytes) == Some(body) request.body().and_then(reqwest::Body::as_bytes) == Some(body)
} }
MatchRequest::Header { name, value } => { MatchRequest::Header { name, value } => {
tracing::trace!(%name, %value, "HEADER");
request request
.headers() .headers()
.iter() .iter()
@ -51,13 +53,29 @@ impl Plan {
request_header_name.as_str() == name && request_header_value == value request_header_name.as_str() == name && request_header_value == value
}) })
} }
MatchRequest::Method(method) => request.method() == http::Method::from(method), MatchRequest::Method(method) => {
MatchRequest::Scheme(scheme) => url.scheme() == scheme, tracing::trace!(%method, "METHOD");
MatchRequest::Host(host) => url.host_str() == Some(host), request.method() == http::Method::from(method)
MatchRequest::Path(path) => url.path() == path, }
MatchRequest::Fragment(fragment) => url.fragment() == Some(fragment), MatchRequest::Scheme(scheme) => {
tracing::trace!(%scheme, "SCHEME");
url.scheme() == scheme
}
MatchRequest::Host(host) => {
tracing::trace!(%host,"HOST");
url.host_str() == Some(host)
}
MatchRequest::Path(path) => {
tracing::trace!(%path,"PATH");
url.path() == path
}
MatchRequest::Fragment(fragment) => {
tracing::trace!(%fragment,"FRAGMENT");
url.fragment() == Some(fragment)
}
MatchRequest::Query { name, value } => url.query_pairs().into_iter().any( MatchRequest::Query { name, value } => url.query_pairs().into_iter().any(
|(request_query_name, request_query_value)| { |(request_query_name, request_query_value)| {
tracing::trace!(%name, %value, "QUERY");
request_query_name.as_ref() == name && request_query_value.as_ref() == value request_query_name.as_ref() == name && request_query_value.as_ref() == value
}, },
), ),
@ -384,7 +402,7 @@ impl<'net> ReqBuilder<'net> {
let client = self.net.client(); let client = self.net.client();
// URL // URL
let mut url = self.url; let mut url = self.url;
tracing::trace!(?url); tracing::trace!(%url);
// Query Parameters // Query Parameters
if !self.query.is_empty() { if !self.query.is_empty() {
url.push('?'); url.push('?');