Skip to content

SCSVEL/eda-contract-n-schema-testing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event-driven services - Event Contract and Schema validations

This is to try and check how to test event-driven services using Kafka + Testcontainers, JSON Schema validation, and simple contract assertions.

Prerequisites:

  • Docker must be running (Testcontainers will start a Kafka broker).
  • Python 3.9+ recommended.

Quick start:

python -m venv .venv
.\.venv\Scripts\activate   # Windows
pip install -r requirements.txt
pytest -q

What it contains:

  • Sample schemas/ – JSON Schemas for orders and payments events.
  • src/producer.py and src/consumer.py – helpers using kafka-python.
  • tests/test_events.py – spins up a Kafka broker with Testcontainers, produces sample events, consumes them and validates with jsonschema.

Docker & Integration Tests

Follow these steps to run the Kafka integration tests locally using Docker.

  • Start Docker Desktop (Windows) or ensure Docker daemon is running.

  • Start Kafka + Zookeeper (uses the repository docker-compose.yml):

cd C:\SHAN\eda-contract-n-schema-testing
.\scripts\start_kafka.ps1
  • Run only the fast, no-Docker tests (default):
C:/SHAN/eda-contract-n-schema-testing/.venv/Scripts/python.exe -m pytest -q
  • Run integration tests that require Docker (marked integration):
C:/SHAN/eda-contract-n-schema-testing/.venv/Scripts/python.exe -m pytest -q -m integration
  • Stop Kafka + Zookeeper when finished:
.\scripts\stop_kafka.ps1

Notes

  • The repo contains three test files:
    • tests/test_events_nodocker.py — unit/contract checks that run without Docker.
    • tests/test_events.py and tests/docker_test_events.py — integration tests marked with integration and skipped automatically if Docker is unavailable. This is just for learning purpose
  • If you run integration tests and testcontainers tries to start containers but Docker is not running, the tests will be skipped.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors