Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lynchborg/ezdc
Easy Testing With Docker Compose in Go.
https://github.com/lynchborg/ezdc
docker-compose go harness testing
Last synced: 2 months ago
JSON representation
Easy Testing With Docker Compose in Go.
- Host: GitHub
- URL: https://github.com/lynchborg/ezdc
- Owner: lynchborg
- License: mit
- Created: 2022-07-15T12:22:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-12T08:42:24.000Z (10 months ago)
- Last Synced: 2024-08-01T05:20:42.090Z (5 months ago)
- Topics: docker-compose, go, harness, testing
- Language: Go
- Homepage:
- Size: 50.8 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-docker - EZDC - Golang test harness for easily setting up tests that rely on services in a docker-compose.yml. By [@byrnedo] (Development with Docker / Testing)
README
# EZDC - Easy Testing With Docker Compose
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/lynchborg/ezdc/blob/master/LICENSE)
[![Go Reference](https://pkg.go.dev/badge/github.com/lynchborg/ezdc.svg)](https://pkg.go.dev/github.com/lynchborg/ezdc)
[![Go Coverage](https://github.com/lynchborg/ezdc/wiki/coverage.svg)](https://raw.githack.com/wiki/lynchborg/ezdc/coverage.html)
[![Go Report Card](https://goreportcard.com/badge/github.com/lynchborg/ezdc)](https://goreportcard.com/report/github.com/lynchborg/ezdc)For easily setting up tests that rely on services in a docker-compose.yml
Do you want your tests to be setup with:
- `docker compose pull`
- `docker compose build`
- `docker compose up`
- Some logic to know containers are ready
- YOUR TESTS HEREFollowed by
- `docker compose down` ?Yes? Then we've got you covered. No? Make a P.R. ⌨️ ❤️
Wrap you `m.Run()` and `ezdc` will take care of spinning up your containers and checking that they're ready before
running your tests.Have a look in the [./examples](./examples) dir for runnable tests.
## Usage
```go
package my_testimport (
"os"
"testing"
"github.com/lynchborg/ezdc"
)func TestMain(m *testing.M) {
h := ezdc.Harness{
ProjectName: "ezdc-example",
Services: []ezdc.Service{
{
Name: "nats",
// will pull before starting tests
Pull: true,
// will wait for nats to listen on localhost:4222
Waiter: ezdc.TcpWaiter{
Port: 4222,
},
},
},
}// h.Run does
// - down (removes volumes)
// - pull (for any configured services with Pull = TRUE)
// - build
// - up
// And when the callback is finished, will run down
c, err := h.Run(context.Background(), m.Run)
if err != nil {
panic(err)
}os.Exit(c)
}
```## Configuration
### Harness
| Setting | |
|-------------|-----------------------------------------------------------------|
| ProjectName | The project name to give to docker-compose. Required |
| File | Path to docker-compose file. Defaults to ./docker-compose.yml |
| Services | Configuration of services. Optional. |
| Logs | Where to send the docker-compose output. Defaults to os.Stdout. |### Services
| Setting | |
|---------|-------------------------------------------------------------------------------------------------------------------|
| Name | Name of the service. Doesn't necessarily have to match any in the docker compose file, but does if `Pull` is TRUE |
| Pull | Pull the image before running tests. Default is false. |
| Waiter | Configures how to declare your service 'ready'. Optional. |## Waiters
Currently supports
- Http (`HttpWaiter`)
- Tcp (`TcpWaiter`)