dockertesting

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2022 License: MIT Imports: 5 Imported by: 0

README

go-dockertesting

An opinionated extension of ory/dockertest which will build a Dockerfile, expose all ports, wait for its health check to pass, and return the dockertest.Resource which was created. It will also register a cleanup handler which may be run if the tests aren't killed with C-c. The resource should also be set to expire to ensure no dangling containers.

License

See LICENSE file.

Documentation

Overview

Opinionated ory/dockertest wrapper

Performs the following quality of life improvements:

• Build a Dockerfile

• Give it a unique name

• Expose its ports (like -P)

• Register it for purge if the test cleanup handlers run

• Wait for its health check to pass

• Configure the container to be auto-removed (like --rm)

IMPORTANT: You should use resource.Expire(seconds) to ensure that your
           returned resource is cleaned up in case of the test being killed.

IMPORTANT: You _must_ configure a health check in your Dockerfile.

To use this for testing with a dockerfile which runs a webserver located at test/Dockerfile:

func TestSudoRun(t *testing.T) {
	resource := dockertesting.RunDockerfile(t, "test/Dockerfile")
	resource.Expire(300)
  hp := resource.GetHostPort("80/tcp")
  _, err := http.Get(hp)
  if err != nil {
    t.Fatalf("Failed to get from container: %v", err)
  }
  // when this closes, the container will be purged.
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunDockerfile

func RunDockerfile(t *testing.T, filename string) *dockertest.Resource

Takes a testing.T and the filename of the Dockerfile.

Returns a docker resource

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL