Home

Awesome

EZDC - Easy Testing With Docker Compose

License Go Reference Go Coverage Go Report Card

For easily setting up tests that rely on services in a docker-compose.yml

Do you want your tests to be setup with:

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 dir for runnable tests.

Usage

package my_test

import (
	"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
ProjectNameThe project name to give to docker-compose. Required
FilePath to docker-compose file. Defaults to ./docker-compose.yml
ServicesConfiguration of services. Optional.
LogsWhere to send the docker-compose output. Defaults to os.Stdout.

Services

Setting
NameName of the service. Doesn't necessarily have to match any in the docker compose file, but does if Pull is TRUE
PullPull the image before running tests. Default is false.
WaiterConfigures how to declare your service 'ready'. Optional.

Waiters

Currently supports