Skip to content

Commit c38e050

Browse files
committed
Allow RegistryBuilder responder URLs to be a String
This allows tests to generate dynamic URLs for custom responders.
1 parent b5d772f commit c38e050

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

crates/cargo-test-support/src/registry.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub struct RegistryBuilder {
9797
/// Write the registry in configuration.
9898
configure_registry: bool,
9999
/// API responders.
100-
custom_responders: HashMap<&'static str, Box<dyn Send + Fn(&Request, &HttpServer) -> Response>>,
100+
custom_responders: HashMap<String, Box<dyn Send + Fn(&Request, &HttpServer) -> Response>>,
101101
/// If nonzero, the git index update to be delayed by the given number of seconds.
102102
delayed_index_update: usize,
103103
}
@@ -167,10 +167,11 @@ impl RegistryBuilder {
167167
#[must_use]
168168
pub fn add_responder<R: 'static + Send + Fn(&Request, &HttpServer) -> Response>(
169169
mut self,
170-
url: &'static str,
170+
url: impl Into<String>,
171171
responder: R,
172172
) -> Self {
173-
self.custom_responders.insert(url, Box::new(responder));
173+
self.custom_responders
174+
.insert(url.into(), Box::new(responder));
174175
self
175176
}
176177

@@ -601,7 +602,7 @@ pub struct HttpServer {
601602
addr: SocketAddr,
602603
token: Token,
603604
auth_required: bool,
604-
custom_responders: HashMap<&'static str, Box<dyn Send + Fn(&Request, &HttpServer) -> Response>>,
605+
custom_responders: HashMap<String, Box<dyn Send + Fn(&Request, &HttpServer) -> Response>>,
605606
delayed_index_update: usize,
606607
}
607608

@@ -621,10 +622,7 @@ impl HttpServer {
621622
api_path: PathBuf,
622623
token: Token,
623624
auth_required: bool,
624-
api_responders: HashMap<
625-
&'static str,
626-
Box<dyn Send + Fn(&Request, &HttpServer) -> Response>,
627-
>,
625+
api_responders: HashMap<String, Box<dyn Send + Fn(&Request, &HttpServer) -> Response>>,
628626
delayed_index_update: usize,
629627
) -> HttpServerHandle {
630628
let listener = TcpListener::bind("127.0.0.1:0").unwrap();

0 commit comments

Comments
 (0)