This project demonstrates how to effectively use Hoverfly for API testing in various non-trivial scenarios. It includes examples of capturing, simulating, and managing API interactions using Hoverfly, along with different client generation approaches.
- Comprehensive Hoverfly integration for API testing
- Support for multiple testing modes (capture, simulate, spy)
- Automated test execution in both local and containerized environments
- Client generation using both oapi-codegen and OpenAPI Generator
- Custom simulation post-processing capabilities
- Docker Compose setup for consistent development environment
- Task-based workflow management using Taskfile
- Docker and Docker Compose
- Go 1.23 or later
- Task (taskfile) installed (
go install github.com/go-task/task/v3/cmd/task@latest
)
.
├── api/ # API specifications
├── client/ # Generated API clients
│ ├── oapi/ # oapi-codegen generated client
│ └── openapi/ # OpenAPI Generator client
├── docker/ # Dockerfile definitions
├── testdata/ # Test data and Hoverfly simulations
│ └── hoverfly/ # Hoverfly simulation files
├── tools/ # Project tools
│ └── postprocessor/ # Simulation post-processor
├── docker-compose.yml # Docker services configuration
└── Taskfile.yml # Task definitions
- Clone the repository:
git clone https://github.com/vmyroslav/api-test-demo.git
cd api-test-demo
- Build the containers:
task build:container
Run tests on your local machine:
# Run tests against real API
task test:local
# Run tests with Hoverfly capture mode
task test:local:capture
# Run tests with Hoverfly simulate mode
task test:local:simulate
The project includes a custom post-processor for Hoverfly simulations. To process a simulation:
task hoverfly:process-simulation SIMULATION_FILE=<path> PROCESSOR=default
Available processors:
default
: Standard simulation processornull
: No-op processor
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
[Add your license information here]
- Hoverfly - API virtualization tool
- oapi-codegen - OpenAPI client generator for Go
- OpenAPI Generator - OpenAPI client generator