localstack

package module
v0.0.0-...-7dec792 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 12 Imported by: 0

README

localstack-go

A small framework for managing localstack containers from Go unit tests.

Usage

In your unit test, simply invoke localstack.New to launch the container and return a configured AWS SDK Session.

For example, to test against DynamoDB:

package my_test

import (
    "github.com/WarrenGray/localstack-go"
    "github.com/aws/aws-sdk-go/service/dynamodb"
)


func MyTestCase(t *testing.T) {
    ls, session, err := localstack.New("myTestName")
    if err != nil {
        panic(err)
    }
    
    defer ls.Stop()
    dynamo := dynamodb.New(session)
}

Notes

  • LocalStack containers do not need to be restarted between tests. You may want to move creation of the test container into an init() or SetupSuite() function to improve testing time.
  • At startup, the LocalStack container will not have any resources. You will need to create them using the relevant AWS APIs before interacting with them.

Documentation

Index

Constants

View Source
const (
	ImageName = "localstack/localstack:0.11.2"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LocalStack

type LocalStack struct {
	Name string
}

LocalStack represents a localstack container running on the local system.

func New

func New(name string) (*LocalStack, *session.Session, error)

New creates a LocalStack and session configured to talk to it. noinspection GoUnusedExportedFunction

func (*LocalStack) Start

func (ls *LocalStack) Start() (*session.Session, error)

Start creates and runs a localstack container on a random port. It waits for the container to start and returns an AWS session.Session configured to talk to the container. The existing container is used if it is already running.

func (*LocalStack) Stop

func (ls *LocalStack) Stop() error

Stop kills the localstack container. It is a noop if the container is not running.

Jump to

Keyboard shortcuts

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