HashMap::get returns the reference inside hashmap. To return an owned value, it had to move it out of the map (that's what remove would do).
Result<T, E> can be cloned only if both T and E can. reqwest::Response and reqwest::Error are both not Clone.
Your best bet might be probably to generate responses in the MockClient on the fly, without pre-computing them. That is, whatever code is used to create res_req should instead run every time you call MockClient::send_request.
That becomes a bit tricky. What I was looking at doing is to seed the mock with paths and corresponding response in each tests. If I move to generating the response on the fly, it means my implementation will be a global form of all the possible paths and responses...workable but maybe not my preferred approach.
I'll tinker with it a bit and see how it turns out.
Another way might be to store not the Responce itself, but a String, which is generated beforehand while seeding, but converted to the Responce on the fly.
doing something similar to this but now have hit another road block
The Ok(Response::from(http::response::Response::new("hi"))) works because this is just a string, but in real life, the response is a response of a custom struct! And that fails because it does not require the needed traits
error[E0277]: the trait bound `Body: From<Payload>` is not satisfied
--> tests/integration_test.rs:30:27
|
30 | Ok(Response::from(http::response::Response::new(res)))
| -------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<Payload>` is not implemented for `Body`
I think I am going to take a step back and revisit the tests Maybe I just spin up a server in the test and mock that, instead of trying to abstract the components that makes the http requests