Skip to content

Commit 26c61c6

Browse files
committed
Use GOOGLE_CLOUD_PROJECT for BigQuery tests.
This removes dependency on hard-coded project name for the BigQuery REST samples.
1 parent 2c6a7aa commit 26c61c6

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ before_install:
4242
- openssl aes-256-cbc -K $encrypted_eb858daba67b_key -iv $encrypted_eb858daba67b_iv -in secrets.env.enc -out secrets.env -d
4343
&& set +x && source secrets.env && set -x
4444
|| true
45+
- export GOOGLE_CLOUD_PROJECT=java-docs-samples-tests
4546
# Skip the install step, since Maven will download the dependencies we need
4647
# when the test build runs.
4748
# http://stackoverflow.com/q/31945809/101923

bigquery/rest/README.md

+17-5
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,31 @@ Install [Maven](http://maven.apache.org/).
1111

1212
Build your project with:
1313

14-
mvn clean package -DskipTests
14+
mvn clean package -DskipTests
1515

1616
You can then run a given `ClassName` via:
1717

18-
mvn exec:java -Dexec.mainClass=com.example.bigquery.ClassName \
19-
-Dexec.args="any arguments to the app"
18+
mvn exec:java -Dexec.mainClass=com.example.bigquery.ClassName \
19+
-Dexec.args="any arguments to the app"
2020

2121
### Labeling a dataset
2222

2323
[Label a dataset](https://cloud.google.com/bigquery/docs/labeling-datasets).
2424

25-
mvn exec:java -Dexec.mainClass=com.example.bigquery.LabelsSample \
26-
-Dexec.args="project-id dataset-id label-key label-value"
25+
mvn exec:java -Dexec.mainClass=com.example.bigquery.LabelsSample \
26+
-Dexec.args="project-id dataset-id label-key label-value"
27+
28+
## Testing
29+
30+
To run the tests for this sample, first set the `GOOGLE_CLOUD_PROJECT`
31+
environment variable. The project should have a dataset named `test_dataset`
32+
with a table named `test_table`.
33+
34+
export GOOGLE_CLOUD_PROJECT=my-project
35+
36+
Then run the tests with Maven.
37+
38+
mvn clean verify
2739

2840
## Products
2941
- [Google BigQuery][2]

bigquery/rest/src/test/java/com/example/bigquery/Constants.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.example.bigquery;
1818

1919
public class Constants {
20-
public static final String PROJECT_ID = "cloud-samples-tests";
21-
public static final String DATASET_ID = "test_dataset_java";
22-
public static final String TABLE_ID = "test_table_java";
20+
public static final String DATASET_ID = "test_dataset";
21+
public static final String TABLE_ID = "test_table";
2322
}

bigquery/rest/src/test/java/com/example/bigquery/LabelsSampleIT.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
public class LabelsSampleIT {
3434
private ByteArrayOutputStream bout;
3535
private PrintStream out;
36+
private String projectId;
3637

3738
@Before
3839
public void setUp() {
40+
projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
3941
bout = new ByteArrayOutputStream();
4042
out = new PrintStream(bout);
4143
System.setOut(out);
@@ -49,7 +51,7 @@ public void tearDown() {
4951
@Test
5052
public void testLabelDataset() throws Exception {
5153
LabelsSample.main(
52-
new String[] {Constants.PROJECT_ID, Constants.DATASET_ID, "environment", "test"});
54+
new String[] {projectId, Constants.DATASET_ID, "environment", "test"});
5355
String got = bout.toString();
5456
assertThat(got).contains("Updated label \"environment\" with value \"test\"");
5557
}
@@ -58,7 +60,7 @@ public void testLabelDataset() throws Exception {
5860
public void testLabelTable() throws Exception {
5961
LabelsSample.main(
6062
new String[] {
61-
Constants.PROJECT_ID,
63+
projectId,
6264
Constants.DATASET_ID,
6365
Constants.TABLE_ID,
6466
"data-owner",

0 commit comments

Comments
 (0)