@@ -20,33 +20,23 @@ type DynamoDBContainer struct {
2020
2121// Run creates an instance of the DynamoDB container type
2222func Run (ctx context.Context , img string , opts ... testcontainers.ContainerCustomizer ) (* DynamoDBContainer , error ) {
23- req := testcontainers.ContainerRequest {
24- Image : img ,
25- ExposedPorts : []string {string (port )},
26- Entrypoint : []string {"java" , "-Djava.library.path=./DynamoDBLocal_lib" },
27- Cmd : []string {"-jar" , "DynamoDBLocal.jar" },
28- WaitingFor : wait .ForListeningPort (port ),
23+ moduleOpts := []testcontainers.ContainerCustomizer {
24+ testcontainers .WithEntrypoint ("java" , "-Djava.library.path=./DynamoDBLocal_lib" ),
25+ testcontainers .WithCmd ("-jar" , "DynamoDBLocal.jar" ),
26+ testcontainers .WithExposedPorts (port ),
27+ testcontainers .WithWaitStrategy (wait .ForListeningPort (port )),
2928 }
3029
31- genericContainerReq := testcontainers.GenericContainerRequest {
32- ContainerRequest : req ,
33- Started : true ,
34- }
35-
36- for _ , opt := range opts {
37- if err := opt .Customize (& genericContainerReq ); err != nil {
38- return nil , fmt .Errorf ("customize: %w" , err )
39- }
40- }
30+ moduleOpts = append (moduleOpts , opts ... )
4131
42- container , err := testcontainers .GenericContainer (ctx , genericContainerReq )
32+ ctr , err := testcontainers .Run (ctx , img , moduleOpts ... )
4333 var c * DynamoDBContainer
44- if container != nil {
45- c = & DynamoDBContainer {Container : container }
34+ if ctr != nil {
35+ c = & DynamoDBContainer {Container : ctr }
4636 }
4737
4838 if err != nil {
49- return c , fmt .Errorf ("generic container : %w" , err )
39+ return c , fmt .Errorf ("run dynamodb : %w" , err )
5040 }
5141
5242 return c , nil
@@ -60,10 +50,15 @@ func (c *DynamoDBContainer) ConnectionString(ctx context.Context) (string, error
6050// WithSharedDB allows container reuse between successive runs. Data will be persisted
6151func WithSharedDB () testcontainers.CustomizeRequestOption {
6252 return func (req * testcontainers.GenericContainerRequest ) error {
63- req .Cmd = append (req .Cmd , "-sharedDb" )
53+ err := testcontainers .WithCmdArgs ("-sharedDb" )(req )
54+ if err != nil {
55+ return fmt .Errorf ("with shared db: %w" , err )
56+ }
6457
65- req .Reuse = true
66- req .Name = containerName
58+ err = testcontainers .WithReuseByName (containerName )(req )
59+ if err != nil {
60+ return fmt .Errorf ("with reuse by name: %w" , err )
61+ }
6762
6863 return nil
6964 }
@@ -73,8 +68,6 @@ func WithSharedDB() testcontainers.CustomizeRequestOption {
7368func WithDisableTelemetry () testcontainers.CustomizeRequestOption {
7469 return func (req * testcontainers.GenericContainerRequest ) error {
7570 // if other flags (e.g. -sharedDb) exist, append to them
76- req .Cmd = append (req .Cmd , "-disableTelemetry" )
77-
78- return nil
71+ return testcontainers .WithCmdArgs ("-disableTelemetry" )(req )
7972 }
8073}
0 commit comments