package testing

import "github.com/golang-migrate/migrate/v4/testing"

Package testing is used in driver tests and should only be used by migrate tests.

Deprecated: If you'd like to test using Docker images, use package github.com/dhui/dktest instead

Index

Examples

Functions

func ParallelTest

func ParallelTest(t *testing.T, versions []Version, readyFn IsReadyFunc, testFn TestFunc)
Example

Code:

{
	t := &testing.T{} // Should actually be used in a Test

	var isReady = func(i Instance) bool {
		// Return true if Instance is ready to run tests.
		// Don't block here though.
		return true
	}

	// t is *testing.T coming from parent Test(t *testing.T)
	ParallelTest(t, []Version{{Image: "docker_image:9.6"}}, isReady,
		func(t *testing.T, i Instance) {
			// Run your test/s ...
			t.Fatal("...")
		})
}

Types

type DockerContainer

type DockerContainer struct {
	ImageName     string
	ENV           []string
	Cmd           []string
	ContainerId   string
	ContainerName string
	ContainerJSON dockertypes.ContainerJSON
	// contains filtered or unexported fields
}

DockerContainer implements Instance interface

func NewDockerContainer

func NewDockerContainer(t testing.TB, image string, env []string, cmd []string) (*DockerContainer, error)

func (*DockerContainer) Host

func (d *DockerContainer) Host() string

func (*DockerContainer) Inspect

func (d *DockerContainer) Inspect() error

func (*DockerContainer) KeepForDebugging

func (d *DockerContainer) KeepForDebugging()

func (*DockerContainer) Logs

func (d *DockerContainer) Logs() (io.ReadCloser, error)

func (*DockerContainer) NetworkSettings

func (d *DockerContainer) NetworkSettings() dockertypes.NetworkSettings

func (*DockerContainer) Port

func (d *DockerContainer) Port() uint

func (*DockerContainer) PortFor

func (d *DockerContainer) PortFor(cPort int) uint

func (*DockerContainer) PullImage

func (d *DockerContainer) PullImage() (err error)

func (*DockerContainer) Remove

func (d *DockerContainer) Remove() error

func (*DockerContainer) Start

func (d *DockerContainer) Start() error

type Instance

type Instance interface {
	Host() string
	Port() uint
	PortFor(int) uint
	NetworkSettings() dockertypes.NetworkSettings
	KeepForDebugging()
}

type IsReadyFunc

type IsReadyFunc func(Instance) bool

type TestFunc

type TestFunc func(*testing.T, Instance)

type Version

type Version struct {
	Image string
	ENV   []string
	Cmd   []string
}

Source Files

docker.go testing.go

Version
v4.18.1
Published
Sep 8, 2024
Platform
darwin/amd64
Imports
18 packages
Last checked
1 hour ago

Tools for package owners.