-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable conditional answers in MkContainer #19
Comments
I believe this accomplishes part of what we added to the rexsl fork. One question, what is the behavior of take() with respect to the order of requests? For example, if I have two conditional next() statements, the requests for these can arrive in any order. How do I take the request that matched a specific response in order to apply request specific validation to it? |
You should call If you want to make assertions on all of that requests, you should use Let me know if I managed to explain it clear enough :) |
I'm aware of the task, give me some time to find a developer... |
@carlosmiranda it's yours now, please proceed keeping in mind our principles. Feel free to ask any technical questions right here in the ticket |
@carlosmiranda The cost of this task is 30 mins (this is exactly how much will be paid, not less not more), when the task is done |
@carlosmiranda please hold on with implementation... let's clarify the requirements first |
@yegor256 , no problem. |
Maybe I've missed something but we specifically want to validate each request against a unique set of requirements. If the matching of request and response is separated from the validation of requests we cannot know which validation requirements to apply to each request. |
@vjkoskela , @yegor256 , any word on what needs to be done? |
@vjkoskela do you know in advance how many requests are you expecting? |
Not exactly. Most test cases will know the exact number, type and requirements for all requests it is mocking. However, there are test cases that target specific functionality and are more permissive to certain common calls that do not directly affect the test case. For example, a test targeting a specific business case may stub a standard positive response to an authorization request and permit any number of request-responses on that endpoint. |
OK, how about this.
The first one is just calling the second one with a "matching all" matcher. The second one is calling the third one with When requests arrive, the container will check which matchers they match. The first successful match will cause the answer to be returned. Then, the container will decrement the number, until it reaches zero. For example, we want to response to authorization requests always, but only one time to a specific data request:
Makes sense? |
Yes, that makes sense. Is the first form next(MkAnswer) then the lowest priority? e.g. it is only used if no matcher matches the request? |
The priority is set by the order of calls to
This means that when request arrives the container:
In your scenario, when you want authentication request be always satisfied and data request only on certain conditions, configuration will look like:
Any number of auth requests will be satisfied, but only one data request will get its answer. All other data requests will get 500. |
I still think there is a conflict between specifying order and specifying matchers. In our case we don't know the order but we would like to setup rules with matchers and execute the one that matches regardless of order. So if I have the following: container Will the correct response be given if I get the following in any order:
The statement that concerns me, and granted I am not clear on how you intend to implement this, is "gamma will be returned only after beta". Are you implying there is a strict ordering to the expected requests? |
In this example everything will work as you expect. Because you're using matchers in all So, your example will work exactly as you expect. |
My concern in your example is that if after the alpha matching request you receive a request that matches gamma then beta is still returned. You are correct that users can make it work; however, the semantics may be a little surprising and can make it easier to write brittle tests. In our case the semantics were that only one matcher could match a request or else and exception is thrown. I understand that you are doing something more general so that's fine - just my two cents. |
Yeah, as a library we have to be generic.. @carlosmiranda does it all sound clear? can you implement it? |
@yegor256 , @vjkoskela , yeah it seems pretty clear now. If I understand it correctly, we implement I know it's been assigned to me since last week but please do give me a bit more time to implement, it's only been clarified recently. |
@carlosmiranda yeah you got it right |
@dmarkov please note that we need more time here than usual, thanks |
I submitted a pull request for this at #23, please take a look. |
I think we're good with this ticket. I'll add a documentation page soon. @vjkoskela I'll keep you updated by email when the feature is fully ready and documented |
@carlosmiranda 30 mins was added to your account, many thanks for your contribution! |
the feature released in version 1.5 |
Let's introduce a new utility class
MkQueryMatchers
, in order to enable conditional answers inMkContainer
, for example:This means that the answer will be returned only if the request contains header
Content-Type
, which is equals to"text/plain"
and request body contains"say hello"
.By default, when method
next(MkAnswer)
is used (with one argument only), an everything-matching instance ofMatcher<MkQuery>
is used.Besides that, let's add methods
take(Matcher<MkAnswer>)
andtakeAll(Matcher<MkAnswer>)
, and an utility classMkAnswerMatchers
:This means that we're taking all requests received by the container, which were answered with responses that had a header "content-type" with a value "application/json". We're asserting that there were 5 those answers. And all of them had body "say hello" and a header "User-Agent".
The text was updated successfully, but these errors were encountered: