11package org .testcontainers .containers .localstack ;
22
3+ import com .github .dockerjava .api .DockerClient ;
34import lombok .AllArgsConstructor ;
4- import lombok .SneakyThrows ;
5- import org .junit .After ;
65import org .junit .BeforeClass ;
76import org .junit .Test ;
87import org .junit .experimental .runners .Enclosed ;
98import org .junit .runner .RunWith ;
109import 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 ;
1613import java .util .Arrays ;
17- import java .util .function .Consumer ;
1814
1915import static org .rnorth .visibleassertions .VisibleAssertions .assertEquals ;
2016import static org .rnorth .visibleassertions .VisibleAssertions .assertNotEquals ;
2117import static org .rnorth .visibleassertions .VisibleAssertions .assertTrue ;
2218import static org .testcontainers .containers .localstack .LocalStackContainer .Service .S3 ;
2319import 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 ;
2424import static org .testcontainers .containers .localstack .LocalstackTestImages .LOCALSTACK_IMAGE ;
2525
2626@ RunWith (Enclosed .class )
2727public 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}
0 commit comments