From b5ac9cd886dfa1dd5f2b01c639c6f60053214dee Mon Sep 17 00:00:00 2001 From: Ivan Yurchenko Date: Tue, 19 Mar 2024 16:26:39 +0100 Subject: [PATCH] Update external URL in containerIsStarted Testcontainers has the special method for post-start actions. --- .../fakegcsserver/FakeGcsServerContainer.java | 5 +++-- .../fakegcsserver/FakeGcsServerContainerTest.java | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/aiven/testcontainers/fakegcsserver/FakeGcsServerContainer.java b/src/main/java/io/aiven/testcontainers/fakegcsserver/FakeGcsServerContainer.java index 78017e5..48649e8 100644 --- a/src/main/java/io/aiven/testcontainers/fakegcsserver/FakeGcsServerContainer.java +++ b/src/main/java/io/aiven/testcontainers/fakegcsserver/FakeGcsServerContainer.java @@ -23,6 +23,7 @@ import java.net.http.HttpResponse; import java.util.Objects; +import com.github.dockerjava.api.command.InspectContainerResponse; import org.testcontainers.containers.GenericContainer; import org.testcontainers.utility.DockerImageName; @@ -56,8 +57,8 @@ public FakeGcsServerContainer withExternalURL(final String externalUrl) { } @Override - public void start() { - super.start(); + protected void containerIsStarted(final InspectContainerResponse containerInfo) { + super.containerIsStarted(containerInfo); updateExternalUrl(); } diff --git a/src/test/java/io/aiven/testcontainers/fakegcsserver/FakeGcsServerContainerTest.java b/src/test/java/io/aiven/testcontainers/fakegcsserver/FakeGcsServerContainerTest.java index cc7d8ac..6be6ecf 100644 --- a/src/test/java/io/aiven/testcontainers/fakegcsserver/FakeGcsServerContainerTest.java +++ b/src/test/java/io/aiven/testcontainers/fakegcsserver/FakeGcsServerContainerTest.java @@ -16,10 +16,13 @@ package io.aiven.testcontainers.fakegcsserver; +import java.io.ByteArrayInputStream; +import java.io.IOException; import java.util.function.Supplier; import java.util.stream.Stream; import com.google.cloud.NoCredentials; +import com.google.cloud.storage.BlobInfo; import com.google.cloud.storage.BucketInfo; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; @@ -37,7 +40,7 @@ public class FakeGcsServerContainerTest { @ParameterizedTest @MethodSource("provideTestParams") - void test(final Supplier fakeGcsServerContainerSupplier) { + void test(final Supplier fakeGcsServerContainerSupplier) throws IOException { try (final FakeGcsServerContainer fakeGcsServerContainer = fakeGcsServerContainerSupplier.get()) { fakeGcsServerContainer.start(); @@ -49,6 +52,11 @@ void test(final Supplier fakeGcsServerContainerSupplier) .getService(); storage.create(TEST_BUCKET); + + // Perform resumable upload to check that the external URL is configured correctly. + final BlobInfo blobInfo = BlobInfo.newBuilder(TEST_BUCKET, "blob").build(); + final byte[] bytes = new byte[10 * 1024 * 1024]; + storage.createFrom(blobInfo, new ByteArrayInputStream(bytes), 256 * 1024); } }