How do I go about adding provider/producer side tests for asyncapi spec where events are sent to Kafka? #1217
Replies: 4 comments 8 replies
-
Hello @tomknee-accelins, Thanks for reaching out and sharing the details. Specmatic Kafka support can be used for both mocking as well as testing.
The system under test you have described (a service exposing HTTP API to its consumers which produces events as a result of HTTP interactions) is very similar to the sample project number 1 above. The BFF service exposes an OpenAPI HTTP API to its consumers and upon receiving an HTTP request it produces a Kafka message (details of which are in an AsyncAPI spec similar to your setup). The Kafka mock server in this case is used to ascertain that the BFF produced the right message on the right topic and more. Hope this clarifies. The next step here will be to test the application that is consuming the messages in Kafka that the BFF layer produced. However, how we test it depends on the architecture of that application. For example: Does it store the details from the message into a DB, write it to a file, send any further messages etc. Event Driven Architecture has several interaction patterns (fire and forget, request reply, fan out and more) in comparison to sync (which is largely request response). It will be great if you can elaborate on what aspect you are trying to test and then I suggest the approach accordingly. About the Docker image documentation, we are in the process of adding details about running contract tests (which is already available in programmatic setup) from CLI. Apologies for any confusion caused by the Docker image documentation. It will be fixed shortly. Please let me know if you have any questions on this. |
Beta Was this translation helpful? Give feedback.
-
Thank you, this makes sense, I will focus on this part and then come back to discuss the other side, cheers. |
Beta Was this translation helpful? Give feedback.
-
Hi Hari, I have made decent progress now, but when running Maybe I NEED to write tests programatiically, and/or use specific json test fixtures? |
Beta Was this translation helpful? Give feedback.
-
Hi @harikrishnan83, I am getting closer, but still have a couple questions please. I have a RESTful service where I make a submission via a POST request to a specific endpoint (e.g. /api/submit). In order to succeed in the above call, I first need to get a bearer token by sending a POST request to the endpoint '/api/auth/login'. Once I succeed in making a submission to '/api/submit', another service (/api/scan-results) then needs to get called downstream (manually though, unless i code something in for this contract test specifically). When this downstream service is called, an event listener picks this up and sends a message to a kafka topic. Because of these downstream services, how do I handle this with Specmatic, as the examples provided only show the one provider service which instantly sends a message to kafka, rather than another downstream service? Also what about the initial auth call? My current assumption would be that I need to get the API app set up first so that I then just need to do a contract test calling Thanks 🙏 |
Beta Was this translation helpful? Give feedback.
-
I am a bit confused here, I see docs for Kafka stub server but that seems like it should be used more on consumer side? Any leads to look at here would be appreciated. Thanks.
My setup is we have APIs defined in OpenAPI spec and one of those is a KafkaService which then produces events, with another repo consuming those events/messages. I have made an AsyncAPI spec which is in a central contract repo.
Many thanks.
Beta Was this translation helpful? Give feedback.
All reactions