Closed rbarronDecathlon closed 1 year ago
Hello, I can understand it, however I'm questioning about how to know if it's a regex or not. What we can do is try catch the compile and in case of exception mock the raw path, what do you think ?
Yes, if we catch the exception, it should work. I'm unsure what you mean by mocking the raw path? With a try/catch, we need to assign a value to urlPattern in the catch clause
What I mean is we take the raw input of the user and put it onto the mocked url
Closed due to resolution in #121
When creating a mock for an Interaction, if the url string is an invalid regex, compiling it will throw a PatternSyntaxException which will only be caught by MockServer which defaults to a 404 instead of the return status and body from the Given step.
Error occurs in HttpSteps: https://github.com/Decathlon/tzatziki/blob/45876446663d2e7ea420f316c70fc9d328747d88/tzatziki-http/src/main/java/com/decathlon/tzatziki/steps/HttpSteps.java#L163
For example:
When my application then makes a call to "/products?search[]=123", the callback function throws an error which is caught by Mockserver:
This is caused due to the empty square brackets [] which will cause Pattern.compile to throw the exception
Proposed solution:
Only compile the mocked url to a regex if it is one, or if the return body is a template ( with $1 $2 etc ... )
This whole block can also be skipped (?) if the url and return body are literals string https://github.com/Decathlon/tzatziki/blob/45876446663d2e7ea420f316c70fc9d328747d88/tzatziki-http/src/main/java/com/decathlon/tzatziki/steps/HttpSteps.java#L186-L204