karatelabs / karate

Test Automation Made Simple
https://karatelabs.github.io/karate
MIT License
8.25k stars 1.94k forks source link

karate mock server interceptor #2443

Closed sergy8612 closed 3 months ago

sergy8612 commented 12 months ago

Hi @ptrthomas

From this question https://stackoverflow.com/questions/77346337/karate-test-framework-are-there-plans-to-include-runtimehooks-for-mockserver we open this issue.

In our case, we need to implement an interceptor in mock http server to track the requests-responses and the scenario and gather all that info to generate a report, with the scenario, the request and response, to validate them against a swagger (we use https://pactflow.io/ which needs to track the request and responses from the mock server to validate the contracts) and in the validation we need not only the http request and response, but the scenario in the mockserver as well. This allows us to generate the report and the Contract Test in our component tests and in our case saves us lots of work.

Unfortunately we don't have that kind of hook .

I created this interface as a hook which meets these needs by extending the karate MockHandler and MockServer

image

Then I included this interceptor interface as a hook in our customzed mockserver image

image

For these reasons, I'd like to create a pull request as a contribution by including the possibility of adding this intereptor

ptrthomas commented 12 months ago

@sergy8612 I think it is an interesting idea. if you are ok to submit a PR with a nice sample, I will certainly review it and consider it for merge. I may have some requests to change / improve the design, thanks

sergy8612 commented 12 months ago

@sergy8612 I think it is an interesting idea. if you are ok to submit a PR with a nice sample, I will certainly review it and consider it for merge. I may have some requests to change / improve the design, thanks

seems I don't have premissions to push a branch into this repo. Can you enable it?

ptrthomas commented 12 months ago

@sergy8612 the normal PR process works: https://github.com/karatelabs/karate/blob/master/.github/CONTRIBUTING.md

sergy8612 commented 12 months ago

Hi @ptrthomas , here is the PR https://github.com/karatelabs/karate/pull/2445

ptrthomas commented 11 months ago

@sergy8612 thanks ! would be good to have documentation and a better unit-test, but I have merged for now

ptrthomas commented 11 months ago

@sergy8612 FYI 1.5.0.RC2 is available including this merge

ptrthomas commented 3 months ago

@sergy8612 can you see if mocks are working fine for https://github.com/karatelabs/karate/releases/tag/v1.5.0.RC5 - the reason I ask is because I saw some issues in resolving the correct versions of netty in spring-boot projects, so I'm still holding on releasing 1.5.0 final :|

ptrthomas commented 3 months ago

1.5.0 released