Skip to content

DennisDenuto/golang-docker-testsuite

Repository files navigation

gotestwithdocker

Build Status

A testing library (for golang projects) to assist in writing integration tests with docker!.

You specify the docker container you want running for your integration tests.

The library will spin it up for your tests to use and tear it down at the end.

Usage

Inside your test file:

import "github.com/DennisDenuto/golang-docker-testsuite"
import . "gopkg.in/check.v1"


func Test(t *testing.T) { TestingT(t) }

type LocalDockerSuite struct {
	gotestwithdocker.DockerSuite
}

var _ = Suite(&LocalDockerSuite{gotestwithdocker.DockerSuite{ConfigYaml: "./docker-config.yaml"}})

func (s *LocalDockerSuite) TestHappyCase(c *C) {
	// your test code here: 
	// host ip of your test container: os.Getenv("DOCKER_HOST_IP")
	// host port of exposed container port: os.Getenv("DOCKER_PORTS_8080/tcp")
}

minimalistic docker-config.yaml

container_name: some-name
image: a-docker-image

docker-config.yaml with exposed ports:

ports:
	- 8080:8080

docker-config.yaml wait for container to start up from grepping log message

wait:
	log: Some msg from StdOut you should wait for before running tests

docker-config.yaml build a docker image from a DockerFile

container_name: test-container-name
image: image-name-to-use-for-built-docker-image
build:
        dockerfile_dir: ./directory-containing-dockerfile

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

About

golang integration tests with docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages