GeezerVison is showing github.com — Use GOOGLE_CLOUD_PROJECT for BigQuery tests. · keirsan/java-docs-samples@26c61c6
File tree
Expand file treeCollapse file tree
Open diff view settings
src/test/java/com/example/bigquery
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: .travis.yml +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,6 +42,7 @@ before_install: |
42 | 42 | - openssl aes-256-cbc -K $encrypted_eb858daba67b_key -iv $encrypted_eb858daba67b_iv -in secrets.env.enc -out secrets.env -d |
43 | 43 | && set +x && source secrets.env && set -x |
44 | 44 | || true |
| 45 | +- export GOOGLE_CLOUD_PROJECT=java-docs-samples-tests |
45 | 46 | # Skip the install step, since Maven will download the dependencies we need |
46 | 47 | # when the test build runs. |
47 | 48 | # http://stackoverflow.com/q/31945809/101923 |
|
Collapse file
Copy file name to clipboardExpand all lines: bigquery/rest/README.md +17-5Lines changed: 17 additions & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -11,19 +11,31 @@ Install [Maven](http://maven.apache.org/). |
11 | 11 |
|
12 | 12 | Build your project with: |
13 | 13 |
|
14 | | - mvn clean package -DskipTests |
| 14 | + mvn clean package -DskipTests |
15 | 15 |
|
16 | 16 | You can then run a given `ClassName` via: |
17 | 17 |
|
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" |
20 | 20 |
|
21 | 21 | ### Labeling a dataset |
22 | 22 |
|
23 | 23 | [Label a dataset](https://cloud.google.com/bigquery/docs/labeling-datasets). |
24 | 24 |
|
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 |
27 | 39 |
|
28 | 40 | ## Products |
29 | 41 | - [Google BigQuery][2] |
|
Collapse file
Copy file name to clipboardExpand all lines: bigquery/rest/src/test/java/com/example/bigquery/Constants.java +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
17 | 17 | package com.example.bigquery; |
18 | 18 |
|
19 | 19 | 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"; |
23 | 22 | } |
Collapse file
Copy file name to clipboardExpand all lines: bigquery/rest/src/test/java/com/example/bigquery/LabelsSampleIT.java +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
33 | 33 | public class LabelsSampleIT { |
34 | 34 | private ByteArrayOutputStream bout; |
35 | 35 | private PrintStream out; |
| 36 | + private String projectId; |
36 | 37 |
|
37 | 38 | @Before |
38 | 39 | public void setUp() { |
| 40 | + projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); |
39 | 41 | bout = new ByteArrayOutputStream(); |
40 | 42 | out = new PrintStream(bout); |
41 | 43 | System.setOut(out); |
@@ -49,7 +51,7 @@ public void tearDown() { |
49 | 51 | @Test |
50 | 52 | public void testLabelDataset() throws Exception { |
51 | 53 | LabelsSample.main( |
52 | | - new String[] {Constants.PROJECT_ID, Constants.DATASET_ID, "environment", "test"}); |
| 54 | + new String[] {projectId, Constants.DATASET_ID, "environment", "test"}); |
53 | 55 | String got = bout.toString(); |
54 | 56 | assertThat(got).contains("Updated label \"environment\" with value \"test\""); |
55 | 57 | } |
@@ -58,7 +60,7 @@ public void testLabelDataset() throws Exception { |
58 | 60 | public void testLabelTable() throws Exception { |
59 | 61 | LabelsSample.main( |
60 | 62 | new String[] { |
61 | | - Constants.PROJECT_ID, |
| 63 | + projectId, |
62 | 64 | Constants.DATASET_ID, |
63 | 65 | Constants.TABLE_ID, |
64 | 66 | "data-owner", |
|