Skip to content

Commit

Permalink
Merge pull request #9 from Aiven-Open/ivanyu/better-use-testcontainer…
Browse files Browse the repository at this point in the history
…s-framework

Update external URL in containerIsStarted
  • Loading branch information
AnatolyPopov authored Mar 25, 2024
2 parents 8efd8c3 + b5ac9cd commit bd9a835
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 bd9a835

Please sign in to comment.