dockertestx

package module
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package dockertestx is wrapper of ory/dockertest.

dockertestx provides ready specific persistent and containers management to reuse.

Index

Examples

Constants

View Source
const (
	S3AWSAccessKeyID     = "AKIAIOSFODNN7DUMMY"                     // #nosec
	S3AWSSecretAccessKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYDUMMYKEY" // #nosec
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContainerFactory

type ContainerFactory interface {
	// contains filtered or unexported methods
}

ContainerFactory represents how to create docker container

type ContainerOption

type ContainerOption struct {
	// Name of docker container
	// it must be present when use same factories
	Name string

	// Tag of docker image
	Tag string
}

type DynamoDBFactory

type DynamoDBFactory struct{}

type Pool

type Pool struct {
	*dockertest.Pool
	// contains filtered or unexported fields
}

Pool represents a connection to the docker API and is used to create and remove docker images.

func New

func New(opt PoolOption) (*Pool, error)

New Pool instance

Example
package main

import (
	"database/sql"
	"log"

	"github.com/tier4/x-go/dockertestx"
)

func main() {
	p, err := dockertestx.New(dockertestx.PoolOption{})
	if err != nil {
		// handle error
		return
	}
	defer func(p *dockertestx.Pool) {
		err := p.Purge()
		if err != nil {
			log.Fatalln(err)
		}
	}(p)

	dsn, err := p.NewResource(new(dockertestx.PostgresFactory), dockertestx.ContainerOption{
		Tag: "13-alpine",
	})
	if err != nil {
		// handle error
		return
	}

	db, err := sql.Open("postgres", dsn)
	if err != nil {
		// handle error
		return
	}
	defer db.Close()
}
Output:

func (*Pool) ForcePurge

func (p *Pool) ForcePurge() error

ForcePurge regardless KeepContainer option

func (*Pool) NewResource

func (p *Pool) NewResource(factory ContainerFactory, opt ContainerOption) (string, error)

func (*Pool) Purge

func (p *Pool) Purge() error

Purge if KeepContainer option is false

func (*Pool) Save

func (p *Pool) Save() error

Save states to reuse containers next time

type PoolOption

type PoolOption struct {
	// KeepContainer or not
	// if true, write container state to StateStore when calling Pool.Save()
	KeepContainer bool

	// StateStore of docker container state for using container
	// this must be present when KeepContainer is true
	StateStore *os.File
}

type PostgresFactory

type PostgresFactory struct{}

type PrismFactory

type PrismFactory struct {
	// SpecURI is a file path or URL of the OpenAPI Specification.
	SpecURI string

	// HealthCheckPath is the path accessed to verify that the stub server has started.
	// The response status code is ignored.
	// The default is to use the base path.
	HealthCheckPath string
}

type S3Factory

type S3Factory struct{}

type SQSFactory

type SQSFactory struct{}

Jump to

Keyboard shortcuts

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