-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Static mocks feature not working in v0.4.1 #153
Comments
I've also downloaded v0.4.0 and can reproduce similar behaviour with it. Interestingly enough, if I use a different command line that is a blend of the static and dynamic mocking examples (i.e. adds a -u parameter):
the actual result indicates the static mock part of the configuration is correct, but instead of mocking requests it proxies them instead. The static mock information provided is not being used and the requests are sent to the target (sorry test.com!).
|
@akash4393 thoughts? |
@akash4393 , @daveshanley , PR #155 should resolve the argument checking issue noted above. In my development environment I still couldn't get the static mock feature to work correctly. I created the directory and file structures exactly as noted in the documentation. When issuing the command:
the monitor UI showed an unending list of requests to the mock server, even though I'd only issued a single request, and no result was returned via curl. This could be a development environment issue or this feature may require some additional work. |
@DawMatt Are you trying to run the wiremock server with static mocking and without a redirect URL? I'm looking at the PR and it seems like that is what the code seems to be doing. if !(mockMode || len(config.MockModeList) > 0) && len(config.StaticMockDir) == 0 && len(staticMockDir) == 0 && redirectURL == "" && harFlag == "" { So I think if static mocking is enabled, I was thinking we would still have the rest of wiretap work as it would without static mocking. So if mockMode is not enabled and no redirect url is provided, we still want to throw an error since not all urls will be served by the static mock definitions. |
@DawMatt Can you also share the mocks you are defining? I'm able to see the responses from static mocks using curl as you. curl "http://localhost/test" Here's my mock definition {
"request": {
"method": "GET",
"urlPath": "/test"
},
"response": {
"statusCode": 200,
"body": "{\"test\": \"hello\"}"
}
} And this is how I am starting the wiremock server wiremock -u "http://localhost:8089" --static-mock-dir "/path/to/mocks" --port 80 |
Yes. I'm trying to run static mock dir feature without a redirect URL. The change I made to the if statement above was to allow this. Currently it would only work if you set the mockMode flag AND staticMockDir. The documentation for this feature indicates only the staticMockDir argument should be provided so I altered this check to align with that. Otherwise the command errors because no URL was specified. Alternatively I did try specifying a URL. In that instance it insisted on proxying the URL and didn't use the static mocks at all.
Can you please explain what you mean by "the rest of wiretap work as it would without static mocking"? Also can you please share the command line you normally use when using static mock dir? Maybe this is a documentation issue rather than a code issue. |
I'm actually using the command line and mocks included in the documentation without any changes. I started with this to see how the feature works, and then was going to adjust for my purposes. Unfortunately I couldn't get this to work. I've attached the files that I created basd upon the doco. I chose the example without the embedded JSON because this is how we'd want to use this. The command line used was:
Interestingly enough the command line you used includes a URL, but the documentation indicates the new argument shouldn't require a URL to be supplied. |
@akash4393 , a suggestion. Can you please look at the documentation page and verify that if someone steps through that example that the feature will work? Maybe the feature has evolved slightly since the docs were written. I tried to step through the example and couldn't get the feature to work. |
@DawMatt you're 100% right. I revisited the doc and it's confusing since it seems to imply that you can run wiretap just as a static mock server. I will work on updating the doc to make it clearer. That said, if you launch it with a redirect url then it should work, as I described in the comment above So I just tested with the mocks you shared above and it works as expected for me. Note that the static mocks will be served when the entire request definition is matched. So you would need to curl with the expected query params and body. This works - curl --location --request GET 'http://localhost/test?test=ok&arr=1&arr=2' \
--header 'Content-Type: application/json' \
--data '{
"test": "ok"
}' But if I just do this - curl "http://localhost/test" Then it won't work since this request doesn't match the definition you have. Another thing to note, in your json body file, you have the entire response instead of just the json of the body, so the API returns with a body {
"statusCode": 200,
"header": {
"something-header": "test-ok"
},
"body": "{\"test\": \"2\"}"
} Maybe that is what you wanted, but I just wanted to call it out. |
Thanks for providing the additional context here. It allowed me to get the current v0.4.1 release working, without my PR applied. I effectively used the command line from your comment, just needed to change
OK, that makes sense but wasn't something I understood initially. If the docs had a "quick start" section stepping through this example (and mentioning this point) it would be super helpful.
OK, it appears I copied the wrong sample JSON from the docs into the test.json file. I actually meant to use the following:
which returns a more useful result:
Something else I noticed now that I've managed to successfully test the feature. Requests served by the static mock feature don't appear in the monitor UI. Those that don't match a static mock definition, and thus are proxied to the redirection URL, do appear in the monitor UI. From memory the regular wiretap mocking feature does display its requests in the monitor UI. It would seem more consistent if these static mock requests would also show in the monitor UI, but this is a "nice to have". In summary:
|
@akash4393 , I've submitted a PR for the doco ( #156 ) to reflect your feedback here. In it the example has been expanded to include the command lines used to test the example and also show the expected response. I think that should be sufficient to help anyone else using the feature for the first time. |
This is a great summary @DawMatt. I totally agree with you that the static mocking feature can use a lot of improvements. Adding those calls to the monitor UI would be a great first step. |
Issue:
It looks like the fix to issue #150 has disabled the new static mock dir feature.
Steps to reproduce:
wiretap --static-mock-dir .\mocks
Expected result:
Static mocking operates as per documentation page.
Actual result:
The text was updated successfully, but these errors were encountered: