Member-only story
Creating Multiple Test Containers with ory/dockertest in Go
Introduction
Testing in isolated environments is crucial to ensuring the reliability and consistency of applications. However, creating isolated test environments can be challenging when dealing with Go services that interact with multiple dependencies. This library: “ory/dockertest” simplifies the process by enabling developers to spin up Docker containers to test your Go applications.
This blog will illustrate creating multiple test containers for a straightforward REST API in Go, which relies on a Postgresql database. We will focus on writing API tests that involve setting up API and database test containers to execute comprehensive end-to-end tests.
Prerequisites
Before we start, ensure you have the following installed:
- Podman/Docker
- Go
- Git
Project Overview:
You can get started by cloning the project
git clone https://github.com/akoserwal/multi-containers-dockertest
The project consists of the following structure, as shown below.
.
├── Dockerfile [1]
├── LocalTestContainers.go [2]
├── Makefile [3]
├── README.md
├── db…