|
1 | 1 | package org.testcontainers.containers.localstack;
|
2 | 2 |
|
3 | 3 | import com.github.dockerjava.api.DockerClient;
|
4 |
| -import lombok.AllArgsConstructor; |
5 |
| -import org.junit.BeforeClass; |
6 |
| -import org.junit.Test; |
7 |
| -import org.junit.experimental.runners.Enclosed; |
8 |
| -import org.junit.runner.RunWith; |
9 |
| -import org.junit.runners.Parameterized; |
| 4 | +import org.junit.jupiter.api.BeforeAll; |
| 5 | +import org.junit.jupiter.params.ParameterizedTest; |
| 6 | +import org.junit.jupiter.params.provider.Arguments; |
| 7 | +import org.junit.jupiter.params.provider.MethodSource; |
10 | 8 | import org.testcontainers.DockerClientFactory;
|
11 | 9 | import org.testcontainers.containers.localstack.LocalStackContainer.Service;
|
12 | 10 | import org.testcontainers.images.RemoteDockerImage;
|
13 | 11 | import org.testcontainers.utility.DockerImageName;
|
14 | 12 |
|
15 |
| -import java.util.Arrays; |
| 13 | +import java.util.stream.Stream; |
16 | 14 |
|
17 | 15 | import static org.assertj.core.api.Assertions.assertThat;
|
18 | 16 |
|
19 |
| -@RunWith(Enclosed.class) |
20 |
| -public class LegacyModeTest { |
| 17 | +class LegacyModeTest { |
21 | 18 |
|
22 |
| - private static DockerImageName LOCALSTACK_CUSTOM_TAG = DockerImageName |
| 19 | + private static final DockerImageName LOCALSTACK_CUSTOM_TAG = DockerImageName |
23 | 20 | .parse("localstack/localstack:0.12.8")
|
24 | 21 | .withTag("custom");
|
25 | 22 |
|
26 |
| - @RunWith(Parameterized.class) |
27 |
| - @AllArgsConstructor |
28 |
| - public static class Off { |
29 |
| - |
30 |
| - private final String description; |
31 |
| - |
32 |
| - private final LocalStackContainer localstack; |
33 |
| - |
34 |
| - @Parameterized.Parameters(name = "{0}") |
35 |
| - public static Iterable<Object[]> constructors() { |
36 |
| - return Arrays.asList( |
37 |
| - new Object[][] { |
38 |
| - { "0.12", new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_12_IMAGE) }, |
39 |
| - { "0.11", new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_11_IMAGE) }, |
40 |
| - { |
41 |
| - "0.11 with legacy = off", |
42 |
| - new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_11_IMAGE, false), |
43 |
| - }, |
44 |
| - } |
45 |
| - ); |
46 |
| - } |
47 |
| - |
48 |
| - @Test |
49 |
| - public void samePortIsExposedForAllServices() { |
50 |
| - localstack.withServices(Service.S3, Service.SQS); |
51 |
| - localstack.start(); |
52 |
| - |
53 |
| - try { |
54 |
| - assertThat(localstack.getExposedPorts()).as("A single port is exposed").hasSize(1); |
55 |
| - assertThat(localstack.getEndpointOverride(Service.SQS).toString()) |
56 |
| - .as("Endpoint overrides are different") |
57 |
| - .isEqualTo(localstack.getEndpointOverride(Service.S3).toString()); |
58 |
| - assertThat(localstack.getEndpointOverride(Service.SQS).toString()) |
59 |
| - .as("Endpoint configuration have different endpoints") |
60 |
| - .isEqualTo(localstack.getEndpointOverride(Service.S3).toString()); |
61 |
| - } finally { |
62 |
| - localstack.stop(); |
63 |
| - } |
64 |
| - } |
| 23 | + @BeforeAll |
| 24 | + static void setup() { |
| 25 | + DockerClient dockerClient = DockerClientFactory.instance().client(); |
| 26 | + dockerClient |
| 27 | + .tagImageCmd( |
| 28 | + new RemoteDockerImage(LocalstackTestImages.LOCALSTACK_0_12_IMAGE).get(), |
| 29 | + LOCALSTACK_CUSTOM_TAG.getRepository(), |
| 30 | + LOCALSTACK_CUSTOM_TAG.getVersionPart() |
| 31 | + ) |
| 32 | + .exec(); |
65 | 33 | }
|
66 | 34 |
|
67 |
| - @RunWith(Parameterized.class) |
68 |
| - @AllArgsConstructor |
69 |
| - public static class On { |
70 |
| - |
71 |
| - private final String description; |
72 |
| - |
73 |
| - private final LocalStackContainer localstack; |
74 |
| - |
75 |
| - @BeforeClass |
76 |
| - public static void createCustomTag() { |
77 |
| - DockerClient dockerClient = DockerClientFactory.instance().client(); |
78 |
| - dockerClient |
79 |
| - .tagImageCmd( |
80 |
| - new RemoteDockerImage(LocalstackTestImages.LOCALSTACK_0_12_IMAGE).get(), |
81 |
| - LOCALSTACK_CUSTOM_TAG.getRepository(), |
82 |
| - LOCALSTACK_CUSTOM_TAG.getVersionPart() |
83 |
| - ) |
84 |
| - .exec(); |
85 |
| - } |
| 35 | + static Stream<Arguments> localstackVersionWithLegacyOff() { |
| 36 | + return Stream.of( |
| 37 | + Arguments.arguments("0.12", new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_12_IMAGE)), |
| 38 | + Arguments.arguments("0.11", new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_11_IMAGE)), |
| 39 | + Arguments.arguments( |
| 40 | + "0.11 with legacy = off", |
| 41 | + new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_11_IMAGE, false) |
| 42 | + ) |
| 43 | + ); |
| 44 | + } |
86 | 45 |
|
87 |
| - @Parameterized.Parameters(name = "{0}") |
88 |
| - public static Iterable<Object[]> constructors() { |
89 |
| - return Arrays.asList( |
90 |
| - new Object[][] { |
91 |
| - { "0.10", new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_10_IMAGE) }, |
92 |
| - { "custom", new LocalStackContainer(LOCALSTACK_CUSTOM_TAG) }, |
93 |
| - { |
94 |
| - "0.11 with legacy = on", |
95 |
| - new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_11_IMAGE, true), |
96 |
| - }, |
97 |
| - } |
98 |
| - ); |
| 46 | + @ParameterizedTest(name = "{0}") |
| 47 | + @MethodSource("localstackVersionWithLegacyOff") |
| 48 | + void samePortIsExposedForAllServices(String description, LocalStackContainer localstack) { |
| 49 | + localstack.withServices(Service.S3, Service.SQS); |
| 50 | + localstack.start(); |
| 51 | + |
| 52 | + try { |
| 53 | + assertThat(localstack.getExposedPorts()).as("A single port is exposed").hasSize(1); |
| 54 | + assertThat(localstack.getEndpointOverride(Service.SQS).toString()) |
| 55 | + .as("Endpoint overrides are different") |
| 56 | + .isEqualTo(localstack.getEndpointOverride(Service.S3).toString()); |
| 57 | + assertThat(localstack.getEndpointOverride(Service.SQS).toString()) |
| 58 | + .as("Endpoint configuration have different endpoints") |
| 59 | + .isEqualTo(localstack.getEndpointOverride(Service.S3).toString()); |
| 60 | + } finally { |
| 61 | + localstack.stop(); |
99 | 62 | }
|
| 63 | + } |
100 | 64 |
|
101 |
| - @Test |
102 |
| - public void differentPortsAreExposed() { |
103 |
| - localstack.withServices(Service.S3, Service.SQS); |
104 |
| - localstack.start(); |
| 65 | + public static Stream<Arguments> localstackVersionWithLegacyOn() { |
| 66 | + return Stream.of( |
| 67 | + Arguments.arguments("0.10", new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_10_IMAGE)), |
| 68 | + Arguments.arguments("custom", new LocalStackContainer(LOCALSTACK_CUSTOM_TAG)), |
| 69 | + Arguments.arguments( |
| 70 | + "0.11 with legacy = on", |
| 71 | + new LocalStackContainer(LocalstackTestImages.LOCALSTACK_0_11_IMAGE, true) |
| 72 | + ) |
| 73 | + ); |
| 74 | + } |
105 | 75 |
|
106 |
| - try { |
107 |
| - assertThat(localstack.getExposedPorts()).as("Multiple ports are exposed").hasSizeGreaterThan(1); |
108 |
| - assertThat(localstack.getEndpointOverride(Service.SQS).toString()) |
109 |
| - .as("Endpoint overrides are different") |
110 |
| - .isNotEqualTo(localstack.getEndpointOverride(Service.S3).toString()); |
111 |
| - assertThat(localstack.getEndpointOverride(Service.SQS).toString()) |
112 |
| - .as("Endpoint configuration have different endpoints") |
113 |
| - .isNotEqualTo(localstack.getEndpointOverride(Service.S3).toString()); |
114 |
| - } finally { |
115 |
| - localstack.stop(); |
116 |
| - } |
| 76 | + @ParameterizedTest(name = "{0}") |
| 77 | + @MethodSource("localstackVersionWithLegacyOn") |
| 78 | + void differentPortsAreExposed(String description, LocalStackContainer localstack) { |
| 79 | + localstack.withServices(Service.S3, Service.SQS); |
| 80 | + localstack.start(); |
| 81 | + |
| 82 | + try { |
| 83 | + assertThat(localstack.getExposedPorts()).as("Multiple ports are exposed").hasSizeGreaterThan(1); |
| 84 | + assertThat(localstack.getEndpointOverride(Service.SQS).toString()) |
| 85 | + .as("Endpoint overrides are different") |
| 86 | + .isNotEqualTo(localstack.getEndpointOverride(Service.S3).toString()); |
| 87 | + assertThat(localstack.getEndpointOverride(Service.SQS).toString()) |
| 88 | + .as("Endpoint configuration have different endpoints") |
| 89 | + .isNotEqualTo(localstack.getEndpointOverride(Service.S3).toString()); |
| 90 | + } finally { |
| 91 | + localstack.stop(); |
117 | 92 | }
|
118 | 93 | }
|
119 | 94 |
|
120 |
| - @RunWith(Parameterized.class) |
121 |
| - @AllArgsConstructor |
122 |
| - public static class LegacyModeUnitTest { |
123 |
| - |
124 |
| - private final String version; |
125 |
| - |
126 |
| - private final boolean shouldUseLegacyMode; |
127 |
| - |
128 |
| - @Parameterized.Parameters(name = "{0} - {1}") |
129 |
| - public static Iterable<Object[]> constructors() { |
130 |
| - return Arrays.asList( |
131 |
| - new Object[][] { |
132 |
| - { "latest", false }, |
133 |
| - { "s3-latest", false }, |
134 |
| - { "latest-bigdata", false }, |
135 |
| - { "3.4.0-bigdata", false }, |
136 |
| - { "3.4.0@sha256:54fcf172f6ff70909e1e26652c3bb4587282890aff0d02c20aa7695469476ac0", false }, |
137 |
| - { "1.4@sha256:7badf31c550f81151c485980e17542592942d7f05acc09723c5f276d41b5927d", false }, |
138 |
| - { "3.4.0", false }, |
139 |
| - { "0.12", false }, |
140 |
| - { "0.11", false }, |
141 |
| - { "sha256:8bf0d744fea26603f2b11ef7206edb38375ef954258afaeda96532a6c9c1ab8b", false }, |
142 |
| - { "0.10.7@sha256:45ef287e29af7285c6e4013fafea1e3567c167cd22d12282f0a5f9c7894b1c5f", true }, |
143 |
| - { "0.10.7", true }, |
144 |
| - { "0.9.6", true }, |
145 |
| - } |
146 |
| - ); |
147 |
| - } |
| 95 | + public static Stream<Arguments> constructors() { |
| 96 | + return Stream.of( |
| 97 | + Arguments.arguments("latest", false), |
| 98 | + Arguments.arguments("s3-latest", false), |
| 99 | + Arguments.arguments("latest-bigdata", false), |
| 100 | + Arguments.arguments("3.4.0-bigdata", false), |
| 101 | + Arguments.arguments("3.4.0@sha256:54fcf172f6ff70909e1e26652c3bb4587282890aff0d02c20aa7695469476ac0", false), |
| 102 | + Arguments.arguments("1.4@sha256:7badf31c550f81151c485980e17542592942d7f05acc09723c5f276d41b5927d", false), |
| 103 | + Arguments.arguments("3.4.0", false), |
| 104 | + Arguments.arguments("0.12", false), |
| 105 | + Arguments.arguments("0.11", false), |
| 106 | + Arguments.arguments("sha256:8bf0d744fea26603f2b11ef7206edb38375ef954258afaeda96532a6c9c1ab8b", false), |
| 107 | + Arguments.arguments("0.10.7@sha256:45ef287e29af7285c6e4013fafea1e3567c167cd22d12282f0a5f9c7894b1c5f", true), |
| 108 | + Arguments.arguments("0.10.7", true), |
| 109 | + Arguments.arguments("0.9.6", true) |
| 110 | + ); |
| 111 | + } |
148 | 112 |
|
149 |
| - @Test |
150 |
| - public void samePortIsExposedForAllServices() { |
151 |
| - assertThat(LocalStackContainer.shouldRunInLegacyMode(version)).isEqualTo(shouldUseLegacyMode); |
152 |
| - } |
| 113 | + @ParameterizedTest |
| 114 | + @MethodSource("constructors") |
| 115 | + void testLegacyMode(String version, boolean shouldUseLegacyMode) { |
| 116 | + assertThat(LocalStackContainer.shouldRunInLegacyMode(version)).isEqualTo(shouldUseLegacyMode); |
153 | 117 | }
|
154 | 118 | }
|
0 commit comments