Skip to content

Commit

Permalink
Update external URL in containerIsStarted
Browse files Browse the repository at this point in the history
Testcontainers has the special method for post-start actions.
  • Loading branch information
ivanyu committed Mar 19, 2024
1 parent bd52b67 commit b5ac9cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +40,7 @@ public class FakeGcsServerContainerTest {

@ParameterizedTest
@MethodSource("provideTestParams")
void test(final Supplier<FakeGcsServerContainer> fakeGcsServerContainerSupplier) {
void test(final Supplier<FakeGcsServerContainer> fakeGcsServerContainerSupplier) throws IOException {
try (final FakeGcsServerContainer fakeGcsServerContainer = fakeGcsServerContainerSupplier.get()) {
fakeGcsServerContainer.start();

Expand All @@ -49,6 +52,11 @@ void test(final Supplier<FakeGcsServerContainer> 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);
}
}

Expand Down

0 comments on commit b5ac9cd

Please sign in to comment.