LukeMathWalker / wiremock-rs

HTTP mocking to test Rust applications.
Apache License 2.0
631 stars 73 forks source link

Print more info when expectations are not verified #31

Closed tl-marco-ieni closed 3 years ago

tl-marco-ieni commented 3 years ago

Problem

Right now when expectations are not satisfied a message similar to this one is showed:

thread panicked at 'Verification failed: mock expectations have not been satisfied.',

It would be nice to print also expected and actual number of times the server was called. They are compared here:

https://github.com/LukeMathWalker/wiremock-rs/blob/40edf7309e2d3680035a15ecf5d306a219fff99a/src/active_mock.rs#L45-L52

Proposed solution

This method:

https://github.com/LukeMathWalker/wiremock-rs/blob/40edf7309e2d3680035a15ecf5d306a219fff99a/src/mock_set.rs#L48-L50

instead of returning bool should return something like:

enum VerificationOutcome {
    Correct,
    Incorrect(Vec<ActiveMock>),
}

where Incorrect contains all the ActiveMocks that are not verified.

This vector should be printed in some way here:

https://github.com/LukeMathWalker/wiremock-rs/blob/40edf7309e2d3680035a15ecf5d306a219fff99a/src/mock_server.rs#L253-L261

I would like to work on this. Do you like the proposed solution?

LukeMathWalker commented 3 years ago

I like the idea in principle - how do we print a non-matched Mock though? I feel this is the real open question.

MarcoIeni commented 3 years ago

Something like: Verification failed: expected number of matching incoming requests: {}, actual: {}

LukeMathWalker commented 3 years ago

That works when you only have one mock mounted on a server, but often you'll have two or more and it's trickier to determine which of those has failed to match.

I am considering the idea of adding a second String parameter to .expect to be displayed when verification fails for that mock. A bit like expect on Option.

MarcoIeni commented 3 years ago

That works when you only have one mock mounted on a server, but often you'll have two or more and it's trickier to determine which of those has failed to match.

Yes, I know, but it's better than nothing.

I am considering the idea of adding a second String parameter to .expect to be displayed when verification fails for that mock. A bit like expect on Option.

Sounds good!

LukeMathWalker commented 3 years ago

Let's go with the second parameter on expect. Do you want to work on this?

MarcoIeni commented 3 years ago

sure!