Closed mbechto closed 7 months ago
I'm quite happy to add a Debug
implementation, but I would prefer to see a #[derive(Debug)]
on MockServer
and a manual implementation of Debug
on BareMockServer
, which prints just the address as you currently do.
Sure, can do. Since it is a tuple struct, it would look like this:
MockServer(address: 127.0.0.1:54942)
or, if implemented canonically:
MockServer(BareMockServer { address: 127.0.0.1:54942 })
Which version do you prefer @LukeMathWalker?
Let's go for the canonical version, since it'll include the variant information which can be useful when debugging.
It turned out not as elegant as I hoped... the main problem being that it's not possible to implement Debug
for PooledMockServer
, which is a custom type consisting of deadpool::managed::Object<T>
. Therefore, I needed to implement Debug
for the InnerServer
enum.
And I have now added a test for it, please have a look.
What do you think?
deadpool
's Object
implements Debug
if the type managed by the pool implements Debug
and the manager itself implements Debug
—see https://docs.rs/deadpool/latest/deadpool/managed/struct.Object.html#impl-Debug-for-Object%3CM%3E
So it should be enough to derive Debug
for https://github.com/LukeMathWalker/wiremock-rs/blob/eef4eb5ecc592f3532c79abfa02b0171909bc7a1/src/mock_server/pool.rs#L52
Nice, I wasn't aware of that, thanks!
Using #[derive(Debug)]
on MockServer
all the way down to MockServerPoolManager
gives us this rather lengthy (but indeed very accurate) string:
MockServer(Pooled(Object { inner: Some(ObjectInner { obj: BareMockServer { address: 127.0.0.1:60130 }, metrics: Metrics { created: Instant { tv_sec: 261427, tv_nsec: 447625625 }, recycled: None, recycle_count: 0 } }) }))
And in the unpooled case simply:
MockServer(Bare(BareMockServer { address: 127.0.0.1:60166 }))
Is that fine?
Yup, let's keep maximum fidelity as our first pass at implementing Debug.
Please review @LukeMathWalker
Description of changes:
Provides an implementation for the
std::fmt::Debug
trait forwiremock::MockServer
. I thought let's keep it simple, so it just prints the address:Motivation: cucumber-rs requires all implementations of
cucumber::World
to implementDebug
. Given all members implementDebug
, it can be derived:Of course it is possible to implement
Debug
forWorld
, but less ergonomic. Hence this PR.Please tell me what you think - I am happy to provide any changes if required!
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.