From 928c1dd593b6b6a4a608aeeba9c2f435e5ddc6b9 Mon Sep 17 00:00:00 2001 From: alimhin Date: Mon, 19 Oct 2026 11:47:11 +0200 Subject: [PATCH 1/2] [gcloud] Allow configuring the BigQuery emulator project id --- docs/modules/gcloud.md | 6 ++++++ .../gcloud/BigQueryEmulatorContainer.java | 19 ++++++++++++++++--- .../gcloud/BigQueryEmulatorContainerTest.java | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/docs/modules/gcloud.md b/docs/modules/gcloud.md index 9660461d5a0..af2d289a09b 100644 --- a/docs/modules/gcloud.md +++ b/docs/modules/gcloud.md @@ -30,6 +30,12 @@ Start BigQuery Emulator during a test: [Creating BigQuery Client](../../modules/gcloud/src/test/java/org/testcontainers/gcloud/BigQueryEmulatorContainerTest.java) inside_block:bigQueryClient +The emulator is started with the `test-project` project id by default. Use `withProjectId` to start it with another one: + + +[Starting a BigQuery Emulator container with a custom project id](../../modules/gcloud/src/test/java/org/testcontainers/gcloud/BigQueryEmulatorContainerTest.java) inside_block:emulatorContainerWithProjectId + + ### Bigtable Start Bigtable Emulator during a test: diff --git a/modules/gcloud/src/main/java/org/testcontainers/gcloud/BigQueryEmulatorContainer.java b/modules/gcloud/src/main/java/org/testcontainers/gcloud/BigQueryEmulatorContainer.java index b5d00bf374a..4eed5791e7a 100644 --- a/modules/gcloud/src/main/java/org/testcontainers/gcloud/BigQueryEmulatorContainer.java +++ b/modules/gcloud/src/main/java/org/testcontainers/gcloud/BigQueryEmulatorContainer.java @@ -17,7 +17,9 @@ public class BigQueryEmulatorContainer extends GenericContainer Date: Mon, 19 Oct 2026 14:51:12 +0200 Subject: [PATCH 2/2] [gcloud] Reject a blank BigQuery emulator project id --- .../gcloud/BigQueryEmulatorContainer.java | 5 +++++ .../gcloud/BigQueryEmulatorContainerTest.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/modules/gcloud/src/main/java/org/testcontainers/gcloud/BigQueryEmulatorContainer.java b/modules/gcloud/src/main/java/org/testcontainers/gcloud/BigQueryEmulatorContainer.java index 4eed5791e7a..40d425cfdc1 100644 --- a/modules/gcloud/src/main/java/org/testcontainers/gcloud/BigQueryEmulatorContainer.java +++ b/modules/gcloud/src/main/java/org/testcontainers/gcloud/BigQueryEmulatorContainer.java @@ -1,5 +1,6 @@ package org.testcontainers.gcloud; +import org.apache.commons.lang3.StringUtils; import org.testcontainers.containers.GenericContainer; import org.testcontainers.utility.DockerImageName; @@ -37,8 +38,12 @@ public BigQueryEmulatorContainer(DockerImageName dockerImageName) { * * @param projectId the project id * @return this container + * @throws IllegalArgumentException if {@code projectId} is null or blank */ public BigQueryEmulatorContainer withProjectId(String projectId) { + if (StringUtils.isBlank(projectId)) { + throw new IllegalArgumentException("BigQuery emulator project id cannot be blank"); + } this.projectId = projectId; return withCommand("--project", projectId); } diff --git a/modules/gcloud/src/test/java/org/testcontainers/gcloud/BigQueryEmulatorContainerTest.java b/modules/gcloud/src/test/java/org/testcontainers/gcloud/BigQueryEmulatorContainerTest.java index 2b330d90255..6f7bbc59abf 100644 --- a/modules/gcloud/src/test/java/org/testcontainers/gcloud/BigQueryEmulatorContainerTest.java +++ b/modules/gcloud/src/test/java/org/testcontainers/gcloud/BigQueryEmulatorContainerTest.java @@ -33,6 +33,9 @@ import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; import org.threeten.bp.Duration; import java.math.BigDecimal; @@ -40,6 +43,7 @@ import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class BigQueryEmulatorContainerTest { @@ -209,6 +213,19 @@ void testCustomProjectId() { } } + @ParameterizedTest + @NullAndEmptySource + @ValueSource(strings = { " " }) + void testBlankProjectIdIsRejected(String projectId) { + try ( + BigQueryEmulatorContainer container = new BigQueryEmulatorContainer("ghcr.io/goccy/bigquery-emulator:0.6.5") + ) { + assertThatThrownBy(() -> container.withProjectId(projectId)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("project id"); + } + } + private BigQuery getBigQuery(BigQueryEmulatorContainer container) { String url = container.getEmulatorHttpEndpoint(); return BigQueryOptions