test

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDynamodbPort = "8000"
View Source
const (
	// ErrDuplicateDatabase returns if try to create duplicate database
	ErrDuplicateDatabase = "42P04"
)

Variables

View Source
var DefaultMySQLOptions = SQLOptions{
	Driver:   "mysql",
	Username: "root",
	Password: "my-secret-pw",

	Port: "3307",

	Database: "db0",

	Host: "",
}
View Source
var DefaultPostgreSQLOptions = SQLOptions{
	Driver:   "postgres",
	Username: "admin",
	Password: "12345",

	Port: "5433",

	Database: "postgres",

	Host: "",
}

Functions

func IsDuplicateDatabase added in v1.0.5

func IsDuplicateDatabase(err error) bool

func IsInsideContainer added in v1.0.4

func IsInsideContainer() bool

func RunGoMigrationContainer added in v1.0.5

func RunGoMigrationContainer(dbContainer *SQLContainer, options MigrationOptions) error

RunGoMigrationContainer creates the migration container and connects to the sql database container to run the migration scripts.

func RunMigrationContainer added in v1.0.4

func RunMigrationContainer(dbContainer *SQLContainer, options MigrationOptions) error

RunMigrationContainer creates the migration container and connects to the sql database container to run the migration scripts.

func ToPostgresArgs added in v1.0.5

func ToPostgresArgs(o SQLOptions) (string, error)

Types

type Container

type Container struct {
	Started bool
	// contains filtered or unexported fields
}

func NewDockerContainer

func NewDockerContainer(opts ...Option) *Container

func (*Container) IPAddress added in v1.0.4

func (c *Container) IPAddress() string

IPAddress returns the IP adress of the container.

func (*Container) OnReady added in v1.0.4

func (c *Container) OnReady(initializer ContainerCallback)

func (*Container) Run added in v1.0.4

func (c *Container) Run() error

func (*Container) SetEnvVars added in v1.0.4

func (c *Container) SetEnvVars(envs []string) *Container

func (*Container) SetHealthChecker added in v1.0.4

func (c *Container) SetHealthChecker(checker ContainerCallback) *Container

func (*Container) SetInitializer added in v1.0.4

func (c *Container) SetInitializer(initializer ContainerCallback) *Container

func (*Container) Start

func (c *Container) Start() error

func (*Container) Stop

func (c *Container) Stop() error

func (*Container) Suspend

func (c *Container) Suspend() error

func (*Container) Wait

func (c *Container) Wait() error

type ContainerCallback added in v1.0.4

type ContainerCallback func(*Container) error

func NewDynamodbHealthChecker added in v1.0.4

func NewDynamodbHealthChecker(options DynamodbOptions) ContainerCallback

func NewMySQLHealthChecker added in v1.0.4

func NewMySQLHealthChecker(options SQLOptions) ContainerCallback

func NewPostgreSQLHealthChecker added in v1.0.5

func NewPostgreSQLHealthChecker(options SQLOptions) ContainerCallback

type DynamodbContainer added in v1.0.4

type DynamodbContainer struct {
	*Container
	Options  DynamodbOptions
	Endpoint string
}

func NewDynamodbContainer added in v1.0.4

func NewDynamodbContainer(options DynamodbOptions, containerOptions ...Option) (*DynamodbContainer, error)

func SetupDynamodb added in v1.0.4

func SetupDynamodb() (*DynamodbContainer, error)

func (*DynamodbContainer) Start added in v1.0.4

func (c *DynamodbContainer) Start() error

func (*DynamodbContainer) Teardown added in v1.0.4

func (container *DynamodbContainer) Teardown() error

type DynamodbOptions added in v1.0.4

type DynamodbOptions struct {
	Host   string
	Port   string
	Region string
}

func LoadDynamodbOptions added in v1.0.4

func LoadDynamodbOptions() DynamodbOptions

LoadDynamodbOptions returns the dynamodb options that will be used for the test cases to connect to.

func (DynamodbOptions) Endpoint added in v1.0.4

func (o DynamodbOptions) Endpoint() string

func (DynamodbOptions) MustNewSession added in v1.0.4

func (o DynamodbOptions) MustNewSession() *session.Session

func (*DynamodbOptions) UpdateHostFromContainer added in v1.0.4

func (o *DynamodbOptions) UpdateHostFromContainer(c *Container) error

UpdateHostFromContainer updates the mysql host field according to the current environment

If we're inside the container, we need to override the hostname defined in the option. If not, we should use the default value 127.0.0.1 because we will need to connect to the host port. please note that the TEST_MYSQL_HOST can be overridden.

type Etcdcontainer

type Etcdcontainer struct {
	URL string
	// contains filtered or unexported fields
}

func NewEtcdContainer

func NewEtcdContainer() (*Etcdcontainer, error)

func (*Etcdcontainer) Start

func (container *Etcdcontainer) Start() error

func (*Etcdcontainer) Stop

func (container *Etcdcontainer) Stop() error

func (*Etcdcontainer) Suspend

func (container *Etcdcontainer) Suspend() error

type MigrationOptions added in v1.0.4

type MigrationOptions struct {
	ImageRepository string
	ImageTag        string

	// this command will override the default command.
	// "bundle" "exec" "rake" "db:migrate"
	Command []string
	// override default entrypoint
	Entrypoint []string
}

MigrationOptions for sql migration container

type MySQLContainer

type MySQLContainer struct {
	*SQLContainer
}

func NewMySQLContainer

func NewMySQLContainer(options SQLOptions, containerOptions ...Option) (*MySQLContainer, error)

func SetupMySQL added in v1.0.4

func SetupMySQL() (*MySQLContainer, error)

setup the mysql connection if TEST_MYSQL_HOST is defined, then we will use the connection directly. if not, a mysql container will be started

func (*MySQLContainer) Start

func (container *MySQLContainer) Start() error

func (*MySQLContainer) Teardown added in v1.0.4

func (container *MySQLContainer) Teardown() error

type Option

type Option func(*Container)

func DockerEnv

func DockerEnv(env []string) Option
func DockerRunLink(link string) Option

func Entrypoint added in v1.1.1

func Entrypoint(entrypoint []string) Option

func ExposePorts added in v1.0.4

func ExposePorts(ports ...string) Option

func HealthChecker

func HealthChecker(checker ContainerCallback) Option

func HostPortBindings added in v1.0.4

func HostPortBindings(bindings ...PortBinding) Option

func ImageRepository

func ImageRepository(name string) Option

func ImageTag

func ImageTag(tag string) Option

func ImageTagFromEnv added in v1.0.8

func ImageTagFromEnv(envName, defaultTag string) Option

ImageTagFromEnv loads the image tag from the given environment variable

func Initializer

func Initializer(init ContainerCallback) Option

func Name

func Name(name string) Option

func Ports

func Ports(ports ...int) Option

Ports function automatically combines port bindings and exposes ports of the container

func RunOptions

func RunOptions(args []string) Option

type PortBinding added in v1.0.4

type PortBinding struct {
	ContainerPort string
	HostPort      string
}

type PostgreSQLContainer added in v1.0.5

type PostgreSQLContainer struct {
	*SQLContainer
	Args string
}

func NewPostgreSQLContainer added in v1.0.5

func NewPostgreSQLContainer(options SQLOptions, containerOptions ...Option) (*PostgreSQLContainer, error)

func SetupPostgreSQL added in v1.0.5

func SetupPostgreSQL() (*PostgreSQLContainer, error)

setup the postgresql connection if TEST_POSTGRESQL_HOST is defined, then we will use the connection directly. if not, a postgresql container will be started

func (*PostgreSQLContainer) Start added in v1.0.5

func (container *PostgreSQLContainer) Start() error

func (*PostgreSQLContainer) Teardown added in v1.0.5

func (container *PostgreSQLContainer) Teardown() error

type RabbitMQContainer

type RabbitMQContainer struct {
	URL string
	// contains filtered or unexported fields
}

func NewRabbitMQContainer

func NewRabbitMQContainer() (*RabbitMQContainer, error)

func (*RabbitMQContainer) Start

func (container *RabbitMQContainer) Start() error

func (*RabbitMQContainer) Stop

func (container *RabbitMQContainer) Stop() error

func (*RabbitMQContainer) Suspend

func (container *RabbitMQContainer) Suspend() error

type RedisContainer

type RedisContainer struct {
	URL string
	// contains filtered or unexported fields
}

func NewRedisContainer

func NewRedisContainer() (*RedisContainer, error)

func (*RedisContainer) Start

func (container *RedisContainer) Start() error

func (*RedisContainer) Stop

func (container *RedisContainer) Stop() error

func (*RedisContainer) Suspend

func (container *RedisContainer) Suspend() error

type SQLContainer added in v1.0.5

type SQLContainer struct {
	*Container
	Options SQLOptions
	URL     string
}

type SQLOptions added in v1.0.5

type SQLOptions struct {
	Driver string

	// The following options are used in the connection string and the mysql server container itself.
	Username string
	Password string
	Port     string
	Database string

	// The host address that will be used to build the connection string
	Host string
}

func LoadMySQLOptions added in v1.0.4

func LoadMySQLOptions() SQLOptions

LoadMySQLOptions returns the mysql options that will be used for the test cases to connect to.

func LoadPostgreSQLOptions added in v1.0.5

func LoadPostgreSQLOptions() SQLOptions

LoadPostgreSQLOptions returns the postgresql options that will be used for the test cases to connect to.

func (*SQLOptions) ToConnectionString added in v1.0.5

func (o *SQLOptions) ToConnectionString() (string, error)

func (*SQLOptions) UpdateHostFromContainer added in v1.0.5

func (o *SQLOptions) UpdateHostFromContainer(c *Container) error

UpdateHostFromContainer updates the mysql host field according to the current environment

If we're inside the container, we need to override the hostname defined in the option. If not, we should use the default value 127.0.0.1 because we will need to connect to the host port. please note that the TEST_MYSQL_HOST can be overridden.

Jump to

Keyboard shortcuts

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