s3

package
v0.0.0-...-a5ef5d7 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package dockerutil provides some convience wrappers around the go-dockerclient package.

Index

Constants

View Source
const (
	S3DefaultAccessKey = "access_key"
	S3DefaultSecretKey = "secret_key"
)
View Source
const (
	PostgresDefaultPassword = "password"
)

Variables

View Source
var (
	Logger           io.Writer
	DefaultEndpoint  = "unix:///var/run/docker.sock"
	DefaultClient, _ = NewClient(DefaultEndpoint)
)
View Source
var (
	DefaultTerminateAction       = "PURGE"
	DefaultContainerTimeout uint = 10
)
View Source
var Containers = ContainerConfigs{
	"postgres": &ContainerConfig{
		Image: "postgres:11.2",
		Port:  "5432/tcp",
	},
	"dynamo": &ContainerConfig{

		Image: "peopleperhour/dynamodb",
		Port:  "8000/tcp",
	},
	"s3": &ContainerConfig{
		Image: "minio/minio:RELEASE.2019-03-13T21-59-47Z",
		Port:  "9000/tcp",
		Env: []string{
			"MINIO_BROWSER=off",
			"MINIO_UPDATE=off",
		},
		Args: []string{
			"server",
			"/home/minio",
		},
	},
	"sns": &ContainerConfig{
		Image: "pafortin/goaws:1.1.2",
		Port:  "4100/tcp",
	},
	"sqs": &ContainerConfig{
		Image: "fingershock/elasticmq:0.14.6",
		Port:  "9324/tcp",
	},
	"kinesis": &ContainerConfig{

		Image: "instructure/kinesalite",
		Port:  "4567/tcp",
		Args: []string{
			"--deleteStreamMs", "0",
		},
	},
	"mysql": &ContainerConfig{

		Image: "mysql:5.6.34",
		Port:  "3306/tcp",
		Init: func(client *Client, config *ContainerConfig) error {
			img, _ := client.InspectImage(mysqlUtf8Image)
			if img == nil {
				if err := buildMysqlImage(config); err != nil {
					return err
				}
			}
			return nil
		},
	},
	"redis": &ContainerConfig{
		Image: "redis:5.0",
		Port:  "6379/tcp",
	},
}

Containers is a map defining a set of named container configurations available for use.

Functions

func Lock

func Lock(name string) *flock

Types

type Client

type Client struct {
	*DockerClient
}

Client wraps the go-dockerclient Client type to add some convenience methods.

It embeds that type so all properties and methods are supported.

func NewClient

func NewClient(endpoint string) (*Client, error)

NewClient creates a new Client object, wrapping the native go-dockerclient Client. See also NewClientFromEnv.

func NewClientFromEnv

func NewClientFromEnv() (*Client, error)

NewClientFromEnv initializes a new Docker client object from environment variables. This is the best way to initialize a client on OS X, where communication with the Docker API is via a self-signed HTTPS endpoint, not a UNIX socket.

func (*Client) CreateContainer

func (client *Client) CreateContainer(opts DockerCreateContainerOptions) (*Container, error)

CreateContainer is a convenience wrapper around Client.CreateContainer() that returns a wrapped Container type.

func (*Client) InspectContainer

func (client *Client) InspectContainer(id string) (*Container, error)

InspectContainer is a convience wrapp around Client.InspectContainer() that returns a wrapped Container type.

func (*Client) PullPublicIfRequired

func (client *Client) PullPublicIfRequired(imageName string) error

PullPublicIfRequired checks to see if the local docker installation has an image available and if not attempts to fetch it from the public docker registry.

It sends any logging information to the Logger defined in this package (if any).

func (*Client) StartNewContainer

func (client *Client) StartNewContainer(containerOpts DockerCreateContainerOptions) (c *Container, err error)

StartNewContainer creates a new container, starts it and retrieves detailed information about it.

type Container

type Container struct {
	*DockerContainer
	// contains filtered or unexported fields
}

Container wraps the go-dockerclient Container type to add some convenience methods.

It embeds that type so all properties and methods are supported.

func StartContainer

func StartContainer(name string, env []string, imageOverride string) (*Container, error)

StartContainer starts a named container configuration, with an optional set of environment variables, and an optional override for the image name.

func StartContainerWithConfig

func StartContainerWithConfig(config *ContainerConfig, env []string, imageOverride string) (*Container, error)

func StartDynamoContainer

func StartDynamoContainer() (*Container, error)

func StartKinesisContainer

func StartKinesisContainer() (*Container, error)

func StartMysqlContainer

func StartMysqlContainer(rootPassword, databaseName string) (*Container, error)

func StartPostgresContainer

func StartPostgresContainer(rootPassword string) (*Container, error)

func StartRedisContainer

func StartRedisContainer() (*Container, error)

func StartS3Container

func StartS3Container(accessKey, secretKey string) (*Container, error)

func StartSNSContainer

func StartSNSContainer() (*Container, error)

func StartSQSContainer

func StartSQSContainer() (*Container, error)

func (*Container) Addr

func (c *Container) Addr() string

Addr returns a complete network address with IP address and exposed port for connecting to the primary service exposed by a container.

func (*Container) IPAddress

func (c *Container) IPAddress() string

IPAddress returns the IP address associated with the container, if any. If we're running under OS X, the returned address will be that of the docker host, as the container's address is not directly accessible.

func (*Container) Port

func (c *Container) Port() string

Port returns the primary exposed port of the container. If we're running under OS X, this will be the mapped port on the Docker host's network address. If the container is running under Linux, this will be the exposed port on the container's network address.

func (*Container) Stop

func (c *Container) Stop(del bool, killTimeout uint, removeVolumes bool) error

Stop stops the running container, optionally removing it afterwards.

func (*Container) WaitForContainer

func (c *Container) WaitForContainer() error

WaitForContainer waits until the container's primary exposed port is listening and available. See WaitForListeningPort().

func (*Container) WaitForListeningPort

func (c *Container) WaitForListeningPort(addr string) error

WaitForListeningPort waits for the container to be available by attempting to connect to the specified address and port. An error will be returned if the connection is not accepted before the timeout of 30 seconds.

type ContainerConfig

type ContainerConfig struct {
	// Image is the name of the Docker image to be started. It will be
	// pulled from docker hub if necessary, or built, if Dockerfile or
	// Init are specified.
	Image string

	// Dockerfile is a custom Dockerfile to build a custom container
	// image from. At this time a custom Dockerfile cannot add
	// additional files to the image, but it can run configuration
	// commands during build. Only one of Dockerfile or Init should be
	// specified.
	Dockerfile string

	// Init specifies a handler function for optionally initializing
	// the docker image. This can be used to build a custom image, for
	// example, with more control than using the Dockerfile
	// parameter. Only one of Dockerfile or Init should be specified.
	Init func(*Client, *ContainerConfig) error

	// Port is a Docker port spec for the primary listening port and
	// protocol to be exposed, e.g. "8000/tcp".
	Port string

	// Env specifies a set of environment variables to pass to the
	// container, if supplied.
	Env []string

	// Args specifies a set of command line args to be passed to the
	// container invocation, if supplied.
	Args []string

	// Request to bind the docker Port to a given HostIP,HostPort
	// This option should only be hard-wired for local tests as
	// other environments, such as the build server, can't guarantee
	// that a particular port will be free
	HostPortBinding DockerHostPortBinding
}

ContainerConfig defines the parameters for launching a Docker container.

func (*ContainerConfig) Build

func (cfg *ContainerConfig) Build() error

type ContainerConfigs

type ContainerConfigs map[string]*ContainerConfig

type DockerAuthConfiguration

type DockerAuthConfiguration = docker.AuthConfiguration

type DockerBuildImageOptions

type DockerBuildImageOptions = docker.BuildImageOptions

type DockerClient

type DockerClient = docker.Client

func DockerNewClient

func DockerNewClient(endpoint string) (*DockerClient, error)

func DockerNewClientFromEnv

func DockerNewClientFromEnv() (*DockerClient, error)

type DockerConfig

type DockerConfig = docker.Config

type DockerContainer

type DockerContainer = docker.Container

type DockerCreateContainerOptions

type DockerCreateContainerOptions = docker.CreateContainerOptions

type DockerHostConfig

type DockerHostConfig = docker.HostConfig

type DockerHostPortBinding

type DockerHostPortBinding = docker.PortBinding

type DockerPort

type DockerPort = docker.Port

type DockerPullImageOptions

type DockerPullImageOptions = docker.PullImageOptions

type DockerRemoveContainerOptions

type DockerRemoveContainerOptions = docker.RemoveContainerOptions

type DynamoSuite

type DynamoSuite struct {
	Suite

	// Dynamo is the AWS SDK client, which will be assigned when
	// SetupSuite() completes successfully.
	Dynamo *dynamodb.DynamoDB
	Config *aws.Config
}

DynamoSuite is a base test suite type which launches a local Amazon DynamoDB-compatible docker container and configures the Amazon AWS SDK's dynamo client to point to it.

Unlike many other local implementations of an AWS backend, the local Dynamo implementation is provided by Amazon. See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html

This will also be home to some helper functions at some point.

func (*DynamoSuite) DeleteAllTables

func (s *DynamoSuite) DeleteAllTables()

DeleteAllTables will, exactly as the name implies, delete *EVERY* table in DynamoDB. Needless to say, you should never, ever, EVER run this against an actual connection to live AWS.

func (*DynamoSuite) ListTableNames

func (s *DynamoSuite) ListTableNames() []string

func (*DynamoSuite) SetupSuite

func (s *DynamoSuite) SetupSuite()

type KinesisSuite

type KinesisSuite struct {
	Suite

	Kinesis  *kinesis.Kinesis
	Config   *aws.Config
	Endpoint string
}

func (*KinesisSuite) CreateStream

func (s *KinesisSuite) CreateStream(name string) string

func (*KinesisSuite) DeleteStream

func (s *KinesisSuite) DeleteStream(name string)

func (*KinesisSuite) GetIterator

func (s *KinesisSuite) GetIterator(stream, shardID string) string

func (*KinesisSuite) GetRecords

func (s *KinesisSuite) GetRecords(stream, shardID string) [][]byte

func (*KinesisSuite) PutRecords

func (s *KinesisSuite) PutRecords(stream string, recs [][]byte)

func (*KinesisSuite) SetupSuite

func (s *KinesisSuite) SetupSuite()

type PostgresSuite

type PostgresSuite struct {
	Suite

	Password string
}

func (*PostgresSuite) SetupSuite

func (s *PostgresSuite) SetupSuite()

type RedisSuite

type RedisSuite struct {
	Suite
	Address string
}

RedisSuite is a base test suite type which launches a local docker container with Redis.

func (*RedisSuite) SetupSuite

func (s *RedisSuite) SetupSuite()

type S3Object

type S3Object struct {
	Path string
	Size int64
}

type S3Suite

type S3Suite struct {
	Suite

	// S3 is the AWS SDK client, which will be assigned when
	// SetupSuite() completes successfully.
	S3        *s3.S3
	AccessKey string
	SecretKey string
	Config    *aws.Config
}

S3Suite is a base test suite type which launches a local Amazon S3-compatible docker container and configures the Amazon AWS SDK's S3 client to point to it.

It also provides a number of wrapper functions for S3 SDK calls that simplify manipulating and inspecting S3 for test case setup and teardown. Rather than returning errors, these functions will cause test errors or failures, to keep the test code minimal.

func (*S3Suite) CreateBucket

func (s *S3Suite) CreateBucket(name string)

func (*S3Suite) DeleteAllObjects

func (s *S3Suite) DeleteAllObjects(bucket string)

func (*S3Suite) DeleteBucket

func (s *S3Suite) DeleteBucket(name string)

func (*S3Suite) DeleteObject

func (s *S3Suite) DeleteObject(bucket, path string)

func (*S3Suite) DeleteObjects

func (s *S3Suite) DeleteObjects(bucket string, paths []string)

func (*S3Suite) GetObject

func (s *S3Suite) GetObject(bucket, path string) []byte

func (*S3Suite) GetObjectWithResponse

func (s *S3Suite) GetObjectWithResponse(bucket, path string) (resp *s3.GetObjectOutput, respData []byte)

func (*S3Suite) GetObjects

func (s *S3Suite) GetObjects(bucket string, paths []string) map[string][]byte

func (*S3Suite) ListObjects

func (s *S3Suite) ListObjects(bucket, prefix string) []S3Object

func (*S3Suite) PutObject

func (s *S3Suite) PutObject(bucket, path, contentType string, data []byte)

func (*S3Suite) PutObjects

func (s *S3Suite) PutObjects(bucket, contentType string, objs map[string][]byte)

func (*S3Suite) SetupSuite

func (s *S3Suite) SetupSuite()

type SNSSuite

type SNSSuite struct {
	Suite
	SNS        *sns.SNS
	Config     *aws.Config
	Endpoint   string
	MetricsReg *metrics.Registry
}

func (*SNSSuite) CreateTopic

func (s *SNSSuite) CreateTopic(name string) string

func (*SNSSuite) DeleteTopic

func (s *SNSSuite) DeleteTopic(arn string)

func (*SNSSuite) SetupSuite

func (s *SNSSuite) SetupSuite()

type SQSSuite

type SQSSuite struct {
	Suite
	SQS           *sqs.SQS
	Config        *aws.Config
	Endpoint      string
	MetricsReg    *metrics.Registry
	EnableLogging bool
}

func (*SQSSuite) CreateQueue

func (s *SQSSuite) CreateQueue(name string) string

func (*SQSSuite) DeleteQueue

func (s *SQSSuite) DeleteQueue(url string)

func (*SQSSuite) SetupSuite

func (s *SQSSuite) SetupSuite()

type Suite

type Suite struct {
	suite.Suite

	// Container is a pointer to the Container structure, which will
	// be assigned after SetupSuite() successfully starts the
	// container.
	Container *Container

	// Start is a function which launches a container, returning the
	// container and an optional error. Each concrete docker test
	// suite must set the Start member before propagating the
	// SetupSuite() call, and should call one of the container
	// starting functions provided by dockerutil.
	//
	// See S3Suite for a concrete example.
	Start func() (*Container, error)
}

Suite provides a base type to use for constructing test suites that depend on docker container. Concrete test suite types must set the Start function.

func (*Suite) SetupSuite

func (s *Suite) SetupSuite()

func (*Suite) TearDownSuite

func (s *Suite) TearDownSuite()

Jump to

Keyboard shortcuts

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