From c38e050fc6a823330b549c8a3db23ba4bf872c24 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 23 Mar 2023 05:20:25 -0700 Subject: [PATCH] Allow RegistryBuilder responder URLs to be a String This allows tests to generate dynamic URLs for custom responders. --- crates/cargo-test-support/src/registry.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index e8b4342c7..41fac3847 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -97,7 +97,7 @@ pub struct RegistryBuilder { /// Write the registry in configuration. configure_registry: bool, /// API responders. - custom_responders: HashMap<&'static str, Box Response>>, + custom_responders: HashMap Response>>, /// If nonzero, the git index update to be delayed by the given number of seconds. delayed_index_update: usize, } @@ -167,10 +167,11 @@ impl RegistryBuilder { #[must_use] pub fn add_responder Response>( mut self, - url: &'static str, + url: impl Into, responder: R, ) -> Self { - self.custom_responders.insert(url, Box::new(responder)); + self.custom_responders + .insert(url.into(), Box::new(responder)); self } @@ -601,7 +602,7 @@ pub struct HttpServer { addr: SocketAddr, token: Token, auth_required: bool, - custom_responders: HashMap<&'static str, Box Response>>, + custom_responders: HashMap Response>>, delayed_index_update: usize, } @@ -621,10 +622,7 @@ impl HttpServer { api_path: PathBuf, token: Token, auth_required: bool, - api_responders: HashMap< - &'static str, - Box Response>, - >, + api_responders: HashMap Response>>, delayed_index_update: usize, ) -> HttpServerHandle { let listener = TcpListener::bind("127.0.0.1:0").unwrap();