godocker

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 18 Imported by: 0

README

godocker

Use ephemeral docker containers for testing.

Usage

func TestThingWithDockerfile(t *testing.T) {
  err := godocker.Run(
    godocker.WithDockerfile("ssh.Dockerfile"),
    godocker.CleanupImage(),      // cleanup docker images afterward
    godocker.CleanupContainer(),  // cleanup docker containers afterward
    godocker.Exec(func (c godocker.Config) (err error) {
      // Run your tests with the docker container
      return
    }),
  )
  if err != nil {
    t.Fatal(err)
  }
}

func TestInImage (t *testing.T) {
  err := godocker.Run(
    godocker.WithImage("mysql:latest"),
    godocker.CleanupContainer(),
    godocker.Exec(func(c godocker.Config) (err error) {
      // Run some queries against the mysql container
      return
    }),
  )
  if err != nil {
    t.Fatal(err)
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTarDirReader

func NewTarDirReader(dir string) *tarDirReader

Convert a directory into a readable tar stream

func Run

func Run(opts ...Opt) (err error)

Types

type Config

type Config struct {
	Name            string
	Cwd             string
	Host            *container.HostConfig
	Network         *network.NetworkingConfig
	Platform        *v1.Platform
	ContainerConfig *container.Config
	ImageBuildOpts  *types.ImageBuildOptions
	ImagePullOpts   *types.ImagePullOptions
	Ctx             context.Context
	ClientOpts      []client.Opt

	Cli       *client.Client
	Container *container.CreateResponse
	ImageTags []string
	// contains filtered or unexported fields
}

type Opt

type Opt = func(config Config) Config

func After

func After(runners ...func(config Config) (err error)) Opt

func CleanupContainer

func CleanupContainer() Opt

func CleanupImage

func CleanupImage() Opt

func Exec

func Exec(runners ...func(config Config) (err error)) Opt

func WithAPIVersion

func WithAPIVersion(version string) Opt

func WithClientOpts

func WithClientOpts(opts ...client.Opt) Opt

func WithConfig

func WithConfig(config Config) Opt

func WithCtx

func WithCtx(ctx context.Context) Opt

func WithCwd

func WithCwd(cwd string) Opt

func WithDockerfile

func WithDockerfile(path string) Opt

func WithImage

func WithImage(image string) Opt

Jump to

Keyboard shortcuts

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