localstack

package module
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 8 Imported by: 5

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var NoopOverrideContainerRequest = func(req testcontainers.ContainerRequest) testcontainers.ContainerRequest {
	return req
}

NoopOverrideContainerRequest returns a helper function that does not override the container request Deprecated: use testcontainers.ContainerCustomizer instead

Functions

func OverrideContainerRequest

func OverrideContainerRequest(r testcontainers.ContainerRequest) func(req testcontainers.ContainerRequest) testcontainers.ContainerRequest

OverrideContainerRequest returns a function that can be used to merge the passed container request with one that is created by the LocalStack container Deprecated: use testcontainers.CustomizeRequest instead

func WithNetwork added in v0.24.0

func WithNetwork(networkName string, alias string) testcontainers.CustomizeRequestOption

WithNetwork creates a network with the given name and attaches the container to it, setting the network alias on that network to the given alias.

Types

type LocalStackContainer

type LocalStackContainer struct {
	testcontainers.Container
}

LocalStackContainer represents the LocalStack container type used in the module

func RunContainer added in v0.20.0

func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*LocalStackContainer, error)

RunContainer creates an instance of the LocalStack container type, being possible to pass a custom request and options: - overrideReq: a function that can be used to override the default container request, usually used to set the image version, environment variables for localstack, etc.

Example
// runLocalstackContainer {
ctx := context.Background()

localstackContainer, err := localstack.RunContainer(ctx,
	testcontainers.WithImage("localstack/localstack:1.4.0"),
)
if err != nil {
	panic(err)
}

// Clean up the container
defer func() {
	if err := localstackContainer.Terminate(ctx); err != nil {
		panic(err)
	}
}()
// }

state, err := localstackContainer.State(ctx)
if err != nil {
	panic(err)
}

fmt.Println(state.Running)
Output:

true
Example (LegacyMode)
ctx := context.Background()

_, err := localstack.RunContainer(
	ctx,
	testcontainers.CustomizeRequest(testcontainers.GenericContainerRequest{
		ContainerRequest: testcontainers.ContainerRequest{
			Image:      "localstack/localstack:0.10.0",
			Env:        map[string]string{"SERVICES": "s3,sqs"},
			WaitingFor: wait.ForLog("Ready.").WithStartupTimeout(5 * time.Minute).WithOccurrence(1),
		},
	}),
)
if err == nil {
	panic(err)
}

fmt.Println(err)
Output:

version=localstack/localstack:0.10.0. Testcontainers for Go does not support running LocalStack in legacy mode. Please use a version >= 0.11.0
Example (WithNetwork)
// localstackWithNetwork {
ctx := context.Background()

nwName := "localstack-network"

_, err := testcontainers.GenericNetwork(ctx, testcontainers.GenericNetworkRequest{
	NetworkRequest: testcontainers.NetworkRequest{
		Name: nwName,
	},
})
if err != nil {
	panic(err)
}

localstackContainer, err := localstack.RunContainer(
	ctx,
	testcontainers.CustomizeRequest(testcontainers.GenericContainerRequest{
		ContainerRequest: testcontainers.ContainerRequest{
			Image:          "localstack/localstack:0.13.0",
			Env:            map[string]string{"SERVICES": "s3,sqs"},
			Networks:       []string{nwName},
			NetworkAliases: map[string][]string{nwName: {"localstack"}},
		},
	}),
)
if err != nil {
	panic(err)
}
// }

// Clean up the container
defer func() {
	if err := localstackContainer.Terminate(ctx); err != nil {
		panic(err)
	}
}()

networks, err := localstackContainer.Networks(ctx)
if err != nil {
	panic(err)
}

fmt.Println(len(networks))
fmt.Println(networks[0])
Output:

1
localstack-network

func StartContainer

func StartContainer(ctx context.Context, overrideReq OverrideContainerRequestOption) (*LocalStackContainer, error)

StartContainer creates an instance of the LocalStack container type, being possible to pass a custom request and options: - overrideReq: a function that can be used to override the default container request, usually used to set the image version, environment variables for localstack, etc. Deprecated: use RunContainer instead

type LocalStackContainerRequest

type LocalStackContainerRequest struct {
	testcontainers.GenericContainerRequest
}

LocalStackContainerRequest represents the LocalStack container request type used in the module to configure the container

type OverrideContainerRequestOption

type OverrideContainerRequestOption func(req testcontainers.ContainerRequest) testcontainers.ContainerRequest

OverrideContainerRequestOption is a type that can be used to configure the Testcontainers container request. The passed request will be merged with the default one. Deprecated: use testcontainers.ContainerCustomizer instead

func (OverrideContainerRequestOption) Customize added in v0.20.0

func (opt OverrideContainerRequestOption) Customize(req *testcontainers.GenericContainerRequest)

Jump to

Keyboard shortcuts

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