Skip to content

Commit 94061b1

Browse files
dmitry-fakurtisvg
andauthored
fix: firestore projectId is hardcoded in the tests (GoogleCloudPlatform#2884)
* fix: firestore projectId is hardcoded in the tests * fix: firestore projectId is hardcoded in the tests * fix: firestore projectId is hardcoded in the tests * fix: firestore projectId is hardcoded in the tests * fix: firestore projectId is hardcoded in the tests * fix: firestore projectId is hardcoded in the tests * Add firestore secrets. * Reorder imports. Co-authored-by: kurtisvg <31518063+kurtisvg@users.noreply.github.com>
1 parent d0a0e74 commit 94061b1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

.kokoro/tests/run_tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ if [[ "$SCRIPT_DEBUG" != "true" ]]; then
7373
source "${KOKORO_GFILE_DIR}/automl_secrets.txt"
7474
# shellcheck source=src/functions_secrets.txt
7575
source "${KOKORO_GFILE_DIR}/functions_secrets.txt"
76+
# spellcheck source=src/firestore_secrets.txt
77+
source "${KOKORO_GFILE_DIR}/firestore_secrets.txt"
7678
# spellcheck source=src/cts_v4_secrets.txt
7779
source "${KOKORO_GFILE_DIR}/cts_v4_secrets.txt"
80+
7881
# Activate service account
7982
gcloud auth activate-service-account \
8083
--key-file="$GOOGLE_APPLICATION_CREDENTIALS" \

firestore/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ the Firestore [documentation](https://cloud.google.com/firestore/docs).
4545

4646
## Tests
4747
Run all tests:
48+
49+
Set the `FIRESTORE_PROJECT_ID` environment variable and run the command:
4850
```
4951
mvn clean verify
5052
```

firestore/src/test/java/com/example/firestore/BaseIntegrationTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.example.firestore;
1818

19+
import static org.junit.Assert.assertNotNull;
20+
1921
import com.example.firestore.snippets.ManageDataSnippetsIT;
2022
import com.example.firestore.snippets.model.City;
2123
import com.google.api.core.ApiFuture;
@@ -32,11 +34,20 @@
3234
*/
3335
public class BaseIntegrationTest {
3436

35-
protected static String projectId = "java-docs-samples-firestore";
37+
protected static String projectId;
3638
protected static Firestore db;
3739

40+
private static String getEnvVar(String varName) {
41+
String value = System.getenv(varName);
42+
assertNotNull(
43+
String.format("Environment variable '%s' must be set to perform these tests.", varName),
44+
value);
45+
return value;
46+
}
47+
3848
@BeforeClass
3949
public static void baseSetup() throws Exception {
50+
projectId = getEnvVar("FIRESTORE_PROJECT_ID");
4051
FirestoreOptions firestoreOptions = FirestoreOptions.getDefaultInstance().toBuilder()
4152
.setProjectId(projectId)
4253
.build();

0 commit comments

Comments
 (0)