Skip to content

Commit 3347710

Browse files
authored
Pin localstack to 0.12.8 (#3981)
1 parent 3c70d08 commit 3347710

File tree

2 files changed

+59
-64
lines changed

2 files changed

+59
-64
lines changed
Lines changed: 54 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
package org.testcontainers.containers.localstack;
22

3+
import com.github.dockerjava.api.DockerClient;
34
import lombok.AllArgsConstructor;
4-
import lombok.SneakyThrows;
5-
import org.junit.After;
65
import org.junit.BeforeClass;
76
import org.junit.Test;
87
import org.junit.experimental.runners.Enclosed;
98
import org.junit.runner.RunWith;
109
import org.junit.runners.Parameterized;
10+
import org.testcontainers.DockerClientFactory;
11+
import org.testcontainers.utility.DockerImageName;
1112

12-
import java.io.BufferedReader;
13-
import java.io.IOException;
14-
import java.io.InputStream;
15-
import java.io.InputStreamReader;
1613
import java.util.Arrays;
17-
import java.util.function.Consumer;
1814

1915
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;
2016
import static org.rnorth.visibleassertions.VisibleAssertions.assertNotEquals;
2117
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;
2218
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.S3;
2319
import static org.testcontainers.containers.localstack.LocalStackContainer.Service.SQS;
20+
import static org.testcontainers.containers.localstack.LocalstackTestImages.LOCALSTACK_0_10_IMAGE;
21+
import static org.testcontainers.containers.localstack.LocalstackTestImages.LOCALSTACK_0_11_IMAGE;
22+
import static org.testcontainers.containers.localstack.LocalstackTestImages.LOCALSTACK_0_12_IMAGE;
23+
import static org.testcontainers.containers.localstack.LocalstackTestImages.LOCALSTACK_0_7_IMAGE;
2424
import static org.testcontainers.containers.localstack.LocalstackTestImages.LOCALSTACK_IMAGE;
2525

2626
@RunWith(Enclosed.class)
2727
public class LegacyModeTest {
28+
private static DockerImageName LOCALSTACK_CUSTOM_TAG = LOCALSTACK_IMAGE.withTag("custom");
2829

2930
@RunWith(Parameterized.class)
3031
@AllArgsConstructor
@@ -35,10 +36,9 @@ public static class Off {
3536
@Parameterized.Parameters(name = "{0}")
3637
public static Iterable<Object[]> constructors() {
3738
return Arrays.asList(new Object[][]{
38-
{"default constructor", new LocalStackContainer(LOCALSTACK_IMAGE)},
39-
{"latest", new LocalStackContainer(LOCALSTACK_IMAGE.withTag("latest"))},
40-
{"0.11.1", new LocalStackContainer(LOCALSTACK_IMAGE.withTag("0.11.1"))},
41-
{"0.7.0 with legacy = off", new LocalStackContainer(LOCALSTACK_IMAGE.withTag("0.7.0"), false)}
39+
{"0.12", new LocalStackContainer(LOCALSTACK_0_12_IMAGE)},
40+
{"0.11", new LocalStackContainer(LOCALSTACK_0_11_IMAGE)},
41+
{"0.7 with legacy = off", new LocalStackContainer(LOCALSTACK_0_7_IMAGE, false)}
4242
});
4343
}
4444

@@ -47,20 +47,19 @@ public void samePortIsExposedForAllServices() {
4747
localstack.withServices(S3, SQS);
4848
localstack.start();
4949

50-
assertTrue("A single port is exposed", localstack.getExposedPorts().size() == 1);
51-
assertEquals(
52-
"Endpoint overrides are different",
53-
localstack.getEndpointOverride(S3).toString(),
54-
localstack.getEndpointOverride(SQS).toString());
55-
assertEquals(
56-
"Endpoint configuration have different endpoints",
57-
localstack.getEndpointConfiguration(S3).getServiceEndpoint(),
58-
localstack.getEndpointConfiguration(SQS).getServiceEndpoint());
59-
}
60-
61-
@After
62-
public void cleanup() {
63-
if (localstack != null) localstack.stop();
50+
try {
51+
assertTrue("A single port is exposed", localstack.getExposedPorts().size() == 1);
52+
assertEquals(
53+
"Endpoint overrides are different",
54+
localstack.getEndpointOverride(S3).toString(),
55+
localstack.getEndpointOverride(SQS).toString());
56+
assertEquals(
57+
"Endpoint configuration have different endpoints",
58+
localstack.getEndpointConfiguration(S3).getServiceEndpoint(),
59+
localstack.getEndpointConfiguration(SQS).getServiceEndpoint());
60+
} finally {
61+
localstack.stop();
62+
}
6463
}
6564
}
6665

@@ -72,16 +71,28 @@ public static class On {
7271

7372
@BeforeClass
7473
public static void createCustomTag() {
75-
run("docker pull localstack/localstack:latest");
76-
run("docker tag localstack/localstack:latest localstack/localstack:custom");
74+
DockerClient dockerClient = DockerClientFactory.instance().client();
75+
DockerClientFactory
76+
.instance()
77+
.checkAndPullImage(
78+
dockerClient,
79+
LOCALSTACK_0_12_IMAGE.asCanonicalNameString()
80+
);
81+
dockerClient
82+
.tagImageCmd(
83+
LOCALSTACK_0_12_IMAGE.asCanonicalNameString(),
84+
LOCALSTACK_CUSTOM_TAG.getRepository(),
85+
LOCALSTACK_CUSTOM_TAG.getVersionPart()
86+
)
87+
.exec();
7788
}
7889

7990
@Parameterized.Parameters(name = "{0}")
8091
public static Iterable<Object[]> constructors() {
8192
return Arrays.asList(new Object[][]{
82-
{"0.10.7", new LocalStackContainer(LOCALSTACK_IMAGE.withTag("0.10.7"))},
83-
{"custom", new LocalStackContainer(LOCALSTACK_IMAGE.withTag("custom"))},
84-
{"0.11.1 with legacy = on", new LocalStackContainer(LOCALSTACK_IMAGE.withTag("0.11.1"), true)}
93+
{"0.10", new LocalStackContainer(LOCALSTACK_0_10_IMAGE)},
94+
{"custom", new LocalStackContainer(LOCALSTACK_CUSTOM_TAG)},
95+
{"0.11 with legacy = on", new LocalStackContainer(LOCALSTACK_0_11_IMAGE, true)}
8596
});
8697
}
8798

@@ -90,39 +101,19 @@ public void differentPortsAreExposed() {
90101
localstack.withServices(S3, SQS);
91102
localstack.start();
92103

93-
assertTrue("Multiple ports are exposed", localstack.getExposedPorts().size() > 1);
94-
assertNotEquals(
95-
"Endpoint overrides are different",
96-
localstack.getEndpointOverride(S3).toString(),
97-
localstack.getEndpointOverride(SQS).toString());
98-
assertNotEquals(
99-
"Endpoint configuration have different endpoints",
100-
localstack.getEndpointConfiguration(S3).getServiceEndpoint(),
101-
localstack.getEndpointConfiguration(SQS).getServiceEndpoint());
102-
}
103-
104-
@After
105-
public void cleanup() {
106-
if (localstack != null) localstack.stop();
107-
}
108-
}
109-
110-
@SneakyThrows
111-
private static void run(String command) {
112-
Process process = Runtime.getRuntime().exec(command);
113-
join(process.getInputStream(), System.out::println);
114-
join(process.getErrorStream(), System.err::println);
115-
process.waitFor();
116-
if (process.exitValue() != 0)
117-
throw new RuntimeException("Failed to execute " + command);
118-
}
119-
120-
private static void join(InputStream stream, Consumer<String> logger) throws IOException {
121-
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream));
122-
String line;
123-
while ((line = bufferedReader.readLine()) != null) {
124-
logger.accept(line);
104+
try {
105+
assertTrue("Multiple ports are exposed", localstack.getExposedPorts().size() > 1);
106+
assertNotEquals(
107+
"Endpoint overrides are different",
108+
localstack.getEndpointOverride(S3).toString(),
109+
localstack.getEndpointOverride(SQS).toString());
110+
assertNotEquals(
111+
"Endpoint configuration have different endpoints",
112+
localstack.getEndpointConfiguration(S3).getServiceEndpoint(),
113+
localstack.getEndpointConfiguration(SQS).getServiceEndpoint());
114+
} finally {
115+
localstack.stop();
116+
}
125117
}
126118
}
127-
128119
}

modules/localstack/src/test/java/org/testcontainers/containers/localstack/LocalstackTestImages.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import org.testcontainers.utility.DockerImageName;
44

55
public interface LocalstackTestImages {
6-
DockerImageName LOCALSTACK_IMAGE = DockerImageName.parse("localstack/localstack:0.11.3");
6+
DockerImageName LOCALSTACK_IMAGE = DockerImageName.parse("localstack/localstack:0.12.8");
7+
DockerImageName LOCALSTACK_0_7_IMAGE = LOCALSTACK_IMAGE.withTag("0.7.0");
8+
DockerImageName LOCALSTACK_0_10_IMAGE = LOCALSTACK_IMAGE.withTag("0.10.7");
9+
DockerImageName LOCALSTACK_0_11_IMAGE = LOCALSTACK_IMAGE.withTag("0.11.3");
10+
DockerImageName LOCALSTACK_0_12_IMAGE = LOCALSTACK_IMAGE.withTag("0.12.8");
711
DockerImageName AWS_CLI_IMAGE = DockerImageName.parse("atlassian/pipelines-awscli:1.16.302");
812
}

0 commit comments

Comments
 (0)