Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to testcontainers-go v0.33.0 #7

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ go run main.go

The example:

1. Starts a Docker container - `dynamodblocal.RunContainer(ctx)`
1. Starts a Docker container - `dynamodblocal.Run(ctx, "amazon/dynamodb-local:2.2.1")`
2. Registers a function (defer) to terminate it at the end of the program - `dynamodbLocalContainer.Terminate(ctx)`
3. Gets the client handle for the DynamoDB (local) instance - `dynamodbLocalContainer.GetDynamoDBClient(context.Background())`
4. Uses the client handle to execute operations. In this case - create a table, add an item, query that item.
Expand Down Expand Up @@ -55,7 +55,7 @@ func main() {

ctx := context.Background()

dynamodbLocalContainer, err := dynamodblocal.RunContainer(ctx)
dynamodbLocalContainer, err := dynamodblocal.Run(ctx, "amazon/dynamodb-local:2.2.1")
if err != nil {
log.Fatalf("failed to start container: %s", err)
}
Expand Down Expand Up @@ -170,22 +170,22 @@ The following configuration parameters are supported: `WithSharedDB` and `WithTe

**WithSharedDB**

```
container, err := dynamodblocal.RunContainer(ctx, WithSharedDB())
```go
container, err := dynamodblocal.Run(ctx, "amazon/dynamodb-local:2.2.1", WithSharedDB())
```

If you use this option, DynamoDB creates a shared database file in which data is stored. This is useful if you want to persist data for e.g. between successive test executions. See [TestIntegrationWithSharedDB in dynamodb_test.go](dynamodb_test.go) for reference.

**WithTelemetryDisabled**

```
container, err := dynamodblocal.RunContainer(ctx, WithTelemetryDisabled())
```go
container, err := dynamodblocal.Run(ctx, "amazon/dynamodb-local:2.2.1", WithTelemetryDisabled())
```

When specified, DynamoDB local will not send any telemetry.

To use these options together:

```go
container, err := dynamodblocal.RunContainer(ctx, WithSharedDB(), WithTelemetryDisabled())
container, err := dynamodblocal.Run(ctx, "amazon/dynamodb-local:2.2.1", WithSharedDB(), WithTelemetryDisabled())
```
16 changes: 13 additions & 3 deletions dynamodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ const (
containerName = "dynamodb_local"
)

// Deprecated: Use Run instead
// RunContainer creates an instance of the dynamodb container type
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*DynamodbLocalContainer, error) {
return Run(ctx, image, opts...)
}

// Run creates an instance of the dynamodb container type
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*DynamodbLocalContainer, error) {
req := testcontainers.ContainerRequest{
Image: image,
Image: img,
ExposedPorts: []string{string(port)},
WaitingFor: wait.ForListeningPort(port),
}
Expand Down Expand Up @@ -89,26 +95,30 @@ func (c *DynamodbLocalContainer) GetDynamoDBClient(ctx context.Context) (*dynamo
// WithSharedDB allows container reuse between successive runs. Data will be persisted
func WithSharedDB() testcontainers.CustomizeRequestOption {

return func(req *testcontainers.GenericContainerRequest) {
return func(req *testcontainers.GenericContainerRequest) error {
if len(req.Cmd) > 0 {
req.Cmd = append(req.Cmd, "-sharedDb")
} else {
req.Cmd = append(req.Cmd, "-jar", "DynamoDBLocal.jar", "-sharedDb")
}
req.Name = containerName
req.Reuse = true

return nil
}
}

// WithTelemetryDisabled - DynamoDB local will not send any telemetry
func WithTelemetryDisabled() testcontainers.CustomizeRequestOption {

return func(req *testcontainers.GenericContainerRequest) {
return func(req *testcontainers.GenericContainerRequest) error {
// if other flags (e.g. -sharedDb) exist, append to them
if len(req.Cmd) > 0 {
req.Cmd = append(req.Cmd, "-disableTelemetry")
} else {
req.Cmd = append(req.Cmd, "-jar", "DynamoDBLocal.jar", "-disableTelemetry")
}

return nil
}
}
23 changes: 14 additions & 9 deletions dynamodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ import (
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
)

const (
tableName = "demo_table"
pkColumnName = "demo_pk"
baseImage = "amazon/dynamodb-local:"
)

var (
image2_2_1 string = baseImage + "2.2.1"
imageInvalid string = baseImage + "0.0.7"
)

func TestIntegration(t *testing.T) {
ctx := context.Background()

container, err := RunContainer(ctx)
container, err := Run(ctx, image2_2_1)
require.NoError(t, err)

// Clean up the container after the test is complete
Expand Down Expand Up @@ -57,7 +62,7 @@ func TestIntegration(t *testing.T) {
func TestIntegrationWithCustomImageVersion(t *testing.T) {
ctx := context.Background()

container, err := RunContainer(ctx, testcontainers.WithImage("amazon/dynamodb-local:2.2.0"))
container, err := Run(ctx, "amazon/dynamodb-local:2.2.0")
require.NoError(t, err)

// Clean up the container after the test is complete
Expand All @@ -72,14 +77,14 @@ func TestIntegrationWithCustomImageVersion(t *testing.T) {
func TestIntegrationWithInvalidCustomImageVersion(t *testing.T) {
ctx := context.Background()

_, err := RunContainer(ctx, testcontainers.WithImage("amazon/dynamodb-local:0.0.7"))
_, err := Run(ctx, imageInvalid)
require.Error(t, err)
}

func TestIntegrationWithoutEndpointResolver(t *testing.T) {
ctx := context.Background()

container, err := RunContainer(ctx)
container, err := Run(ctx, image2_2_1)
require.NoError(t, err, "container should start successfully")

// clean up the container after the test completion
Expand All @@ -99,7 +104,7 @@ func TestIntegrationWithoutEndpointResolver(t *testing.T) {
func TestIntegrationWithSharedDB(t *testing.T) {
ctx := context.Background()

container, err := RunContainer(ctx, WithSharedDB())
container, err := Run(ctx, image2_2_1, WithSharedDB())
require.NoError(t, err)

// Clean up the container after the test is complete
Expand Down Expand Up @@ -156,7 +161,7 @@ func TestIntegrationWithSharedDB(t *testing.T) {
func TestIntegrationWithoutSharedDB(t *testing.T) {
ctx := context.Background()

container, err := RunContainer(ctx)
container, err := Run(ctx, image2_2_1)
require.NoError(t, err)

// Clean up the container after the test is complete
Expand Down Expand Up @@ -201,7 +206,7 @@ func TestIntegrationWithoutSharedDB(t *testing.T) {
func TestContainerShouldStartWithTelemetryDisabled(t *testing.T) {
ctx := context.Background()

container, err := RunContainer(ctx, WithTelemetryDisabled())
container, err := Run(ctx, image2_2_1, WithTelemetryDisabled())
require.NoError(t, err)

// Clean up the container after the test is complete
Expand All @@ -216,7 +221,7 @@ func TestContainerShouldStartWithTelemetryDisabled(t *testing.T) {
func TestContainerShouldStartWithSharedDBEnabledAndTelemetryDisabled(t *testing.T) {
ctx := context.Background()

container, err := RunContainer(ctx, WithSharedDB(), WithTelemetryDisabled())
container, err := Run(ctx, image2_2_1, WithSharedDB(), WithTelemetryDisabled())
require.NoError(t, err)

// Clean up the container after the test is complete
Expand Down
4 changes: 2 additions & 2 deletions examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
dynamodblocal "github.com/abhirockzz/dynamodb-local-testcontainers-go"
)

func ExampleRunContainer() {
func ExampleRun() {
ctx := context.Background()

dynamodbContainer, err := dynamodblocal.RunContainer(ctx)
dynamodbContainer, err := dynamodblocal.Run(ctx, "amazon/dynamodb-local:2.2.1")
if err != nil {
log.Fatalf("failed to start container: %s", err)
}
Expand Down
46 changes: 22 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/abhirockzz/dynamodb-local-testcontainers-go

go 1.20
go 1.21

require (
github.com/aws/aws-sdk-go-v2 v1.24.1
Expand All @@ -9,15 +9,14 @@ require (
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.27.1
github.com/aws/smithy-go v1.19.0
github.com/docker/go-connections v0.5.0
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go v0.27.0
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.33.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.11 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.10 // indirect
Expand All @@ -29,32 +28,33 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.7 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.26.7 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.12 // indirect
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.2+incompatible // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
Expand All @@ -64,16 +64,14 @@ require (
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/tools v0.10.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading