File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed
main/java/org/testcontainers/containers
test/java/org/testcontainers/containers Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -21,13 +21,32 @@ public class DatastoreEmulatorContainer extends GenericContainer<DatastoreEmulat
2121
2222 private static final int HTTP_PORT = 8081 ;
2323
24+ private String flags ;
25+
26+ public DatastoreEmulatorContainer (final String image ) {
27+ this (DockerImageName .parse (image ));
28+ }
29+
2430 public DatastoreEmulatorContainer (final DockerImageName dockerImageName ) {
2531 super (dockerImageName );
2632 dockerImageName .assertCompatibleWith (DEFAULT_IMAGE_NAME );
2733
2834 withExposedPorts (HTTP_PORT );
2935 setWaitStrategy (Wait .forHttp ("/" ).forStatusCode (200 ));
30- withCommand ("/bin/sh" , "-c" , CMD );
36+ }
37+
38+ @ Override
39+ protected void configure () {
40+ String command = CMD ;
41+ if (this .flags != null && !this .flags .isEmpty ()) {
42+ command += " " + this .flags ;
43+ }
44+ withCommand ("/bin/sh" , "-c" , command );
45+ }
46+
47+ public DatastoreEmulatorContainer withFlags (String flags ) {
48+ this .flags = flags ;
49+ return this ;
3150 }
3251
3352 /**
@@ -36,6 +55,6 @@ public DatastoreEmulatorContainer(final DockerImageName dockerImageName) {
3655 * com.google.cloud.ServiceOptions.Builder#setHost(java.lang.String) method.
3756 */
3857 public String getEmulatorEndpoint () {
39- return getHost () + ":" + getMappedPort (8081 );
58+ return getHost () + ":" + getMappedPort (HTTP_PORT );
4059 }
4160}
Original file line number Diff line number Diff line change 1010import org .junit .Test ;
1111import org .testcontainers .utility .DockerImageName ;
1212
13+ import java .io .IOException ;
14+
1315import static org .assertj .core .api .Assertions .assertThat ;
1416
1517public class DatastoreEmulatorContainerTest {
@@ -40,6 +42,36 @@ public void testSimple() {
4042
4143 assertThat (datastore .get (key ).getString ("description" )).isEqualTo ("my description" );
4244 }
45+
4346 // }
4447
48+ @ Test
49+ public void testWithFlags () throws IOException , InterruptedException {
50+ try (
51+ DatastoreEmulatorContainer emulator = new DatastoreEmulatorContainer (
52+ "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators"
53+ )
54+ .withFlags ("--consistency 1.0" )
55+ ) {
56+ emulator .start ();
57+
58+ assertThat (emulator .getContainerInfo ().getConfig ().getCmd ()).anyMatch (e -> e .contains ("--consistency 1.0" ));
59+ assertThat (emulator .execInContainer ("ls" , "/root/.config/" ).getStdout ()).contains ("gcloud" );
60+ }
61+ }
62+
63+ @ Test
64+ public void testWithMultipleFlags () throws IOException , InterruptedException {
65+ try (
66+ DatastoreEmulatorContainer emulator = new DatastoreEmulatorContainer (
67+ "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators"
68+ )
69+ .withFlags ("--consistency 1.0 --data-dir /root/.config/test-gcloud" )
70+ ) {
71+ emulator .start ();
72+
73+ assertThat (emulator .getContainerInfo ().getConfig ().getCmd ()).anyMatch (e -> e .contains ("--consistency 1.0" ));
74+ assertThat (emulator .execInContainer ("ls" , "/root/.config/" ).getStdout ()).contains ("test-gcloud" );
75+ }
76+ }
4577}
You can’t perform that action at this time.
0 commit comments