dynamotest

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

README ¶

dynamotest

Use the power of DynamoDB Local with ory/dockertest, create your DynamoDB test cases with breeze.

🌄 What is dynamotest?

dynamotest is a package to help set up a DynamoDB Local Docker instance on your machine as a part of Go test code. It uses ory/dockertest to start the DynamoDB Local instance in your Go test code, and is configured so that each call to dynamotest.NewDynamoDB(t) will create a dedicated instance to allow parallel testing on multiple Docker instances. The function returns a new DynamoDB client which is already connected to the instance, and thus you can simply start using the client straight away. Also, it provides the clean up function to ensure that the Docker instance gets deleted if clean-up is preferred. If you do not call the clean up function, the instance will keep running, which may be useful for debugging and investigation.

dynamotest also provides a helper function dynamotest.PrepTable(t, client, ...dynamotest.InitialTableSetup) to prepare tables and dataset for setting up the table before hand.

It is also worth noting how this package uses only the v2 version of AWS SDK.

NOTE: It is a prerequisite that you are able to start up Docker container for DynamoDB Local.

🚀 Examples

Minimal Setup Overview
func TestMinimalSetup(t *testing.T) {
	// Create a new DynamoDB Local instance. Second return value can be called
	// to delete the instance.
	client, clean := dynamotest.NewDynamoDB(t)
	defer clean()

	// Prepare table with some data. You can provide as many data set as you
	// need by providing `dynamotest.InitialTableSetup` structs.
	dynamotest.PrepTable(t, client,
		dynamotest.InitialTableSetup{
			Table: &dynamodb.CreateTableInput{
				// Table definition.
			},
			InitialData: []*types.PutRequest{
				// Initial data to populate the table with.
			},
		},
		// Provide as many initial data as you need
	)

	// Now the DynamoDB client, which is connected to the test instance, is
	// ready to be used.
	_ = client
}

Ref: minimal_test.go

Documentation ¶

Index ¶

Constants ¶

This section is empty.

Variables ¶

This section is empty.

Functions ¶

func NewDynamoDB ¶

func NewDynamoDB(t testing.TB) (*dynamodb.Client, func())

NewDynamoDB creates a Docker container with DynamoDB Local, and returns the connected DynamoDB client. Clean up function is returned as well to ensure container gets removed after test is complete.

func PrepTable ¶

func PrepTable(t testing.TB, client *dynamodb.Client, input ...InitialTableSetup)

PrepTable iterates the provided input, creates tables and put items.

Types ¶

type InitialTableSetup ¶

type InitialTableSetup struct {
	Table       *dynamodb.CreateTableInput
	InitialData []*types.PutRequest
}

Jump to

Keyboard shortcuts

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