Kong / kong-pongo

Tooling to run plugin tests with Kong and Kong Enterprise
Apache License 2.0
153 stars 54 forks source link

How to mock multiple json responses using http protocol in a single test case? #396

Closed arcaydian closed 1 year ago

arcaydian commented 1 year ago

I have a lua plugin that, on receiving any request (request-A), sends a new request to a server (server-A) and gets a response (response-A) from the server. After receiving response-A from the server-A, the plugin sets the response-A in the header of the request-A and forwards the request-A to the target server (server-B), which returns response-B

How can I mock two separate servers (server-A and server-B) and assert the returned hardcoded JSON responses (response-A and response-B) received throughout the execution cycle of the plugin in a single test case?

Additional details: Kong version - [3.x-ubuntu-focal] (https://download.konghq.com/gateway-3.x-ubuntu-focal/) Pongo version - 2.6.0 Kong port - 80 Server-A port - 9090 Server-B port - 8080

Tieske commented 1 year ago

The test scaffolding comes with a simple mock backend that echo's the request received. That can be used for server-B. For server-A you can create a separate mock. Use pongo docs to generate the docs, and then check for the shell helper start_kong, it has an example how to create a mock http server.

brentos commented 1 year ago

I use MockServer for cases like this. You can mock many different responses. I have a simple example here

Tieske commented 1 year ago

TIL MockServer! that is really neat @brentos 👍

arcaydian commented 1 year ago

@brentos @Tieske I greatly appreciate your help. I will reopen this issue later if required.