Skip to content

Commit 37f5ee0

Browse files
committed
chore(localstack): using testcontainers.ContainerHost instead of direct relying on testcontainers.DockerProvider.
Signed-off-by: Marat Abrarov <abrarov@gmail.com>
1 parent 19be4cf commit 37f5ee0

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

modules/localstack/localstack.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
9999
envVar = localstackHostEnvVar
100100
}
101101

102-
hostnameExternalReason, err := configureDockerHost(&localStackReq, envVar)
102+
hostnameExternalReason, err := configureDockerHost(&localStackReq, envVar, opts...)
103103
if err != nil {
104104
return nil, err
105105
}
@@ -125,7 +125,7 @@ func StartContainer(ctx context.Context, overrideReq OverrideContainerRequestOpt
125125
return RunContainer(ctx, overrideReq)
126126
}
127127

128-
func configureDockerHost(req *LocalStackContainerRequest, envVar string) (string, error) {
128+
func configureDockerHost(req *LocalStackContainerRequest, envVar string, opts ...testcontainers.ContainerCustomizer) (string, error) {
129129
reason := ""
130130

131131
if _, ok := req.Env[envVar]; ok {
@@ -141,13 +141,7 @@ func configureDockerHost(req *LocalStackContainerRequest, envVar string) (string
141141
return "to match last network alias on container with non-default network", nil
142142
}
143143

144-
dockerProvider, err := testcontainers.NewDockerProvider()
145-
if err != nil {
146-
return reason, err
147-
}
148-
defer dockerProvider.Close()
149-
150-
daemonHost, err := dockerProvider.DaemonHost(context.Background())
144+
daemonHost, err := testcontainers.ContainerHost(context.Background(), opts...)
151145
if err != nil {
152146
return reason, err
153147
}

modules/localstack/localstack_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ func TestConfigureDockerHost(t *testing.T) {
6161
})
6262

6363
t.Run("HOSTNAME_EXTERNAL matches the daemon host because there are no aliases", func(t *testing.T) {
64-
dockerProvider, err := testcontainers.NewDockerProvider()
65-
require.NoError(t, err)
66-
defer dockerProvider.Close()
67-
68-
// because the daemon host could be a remote one, we need to get it from the provider
69-
expectedDaemonHost, err := dockerProvider.DaemonHost(context.Background())
64+
expectedDaemonHost, err := testcontainers.ContainerHost(context.Background())
7065
require.NoError(t, err)
7166

7267
req := generateContainerRequest()

0 commit comments

Comments
 (0)