-
Notifications
You must be signed in to change notification settings - Fork 135
feat(jdbc): add RequestReason connection property
#4094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
cd7fecb
4a149ba
9020da5
9c20a8b
b06484b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,23 @@ public void testHeaderProviderWithInvalidPartner() throws IOException, SQLExcept | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testHeaderProviderWithRequestReason() throws IOException, SQLException { | ||
| String requestReason = "Ticket123"; | ||
| String url = | ||
| "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" | ||
| + "OAuthType=2;ProjectId=MyBigQueryProject;" | ||
| + "OAuthAccessToken=redactedToken;OAuthClientId=redactedToken;" | ||
| + "OAuthClientSecret=redactedToken;RequestReason=" | ||
| + requestReason; | ||
| try (BigQueryConnection connection = new BigQueryConnection(url)) { | ||
| HeaderProvider headerProvider = connection.createHeaderProvider(); | ||
| java.util.Map<String, String> headers = headerProvider.getHeaders(); | ||
| assertTrue(headers.containsKey("x-goog-request-reason")); | ||
| assertEquals(requestReason, headers.get("x-goog-request-reason")); | ||
| } | ||
| } | ||
|
Comment on lines
+168
to
+183
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test covers the happy path well. To improve test coverage, please consider adding another test case for when |
||
|
|
||
| @Test | ||
| public void testWriteAPIConnectionProperties() throws SQLException { | ||
| // Test without connection properties. Defaults to default values. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple of suggestions for this block to improve robustness and maintainability:
x-goog-request-reasonheader even ifrequestReasonis an empty string or just whitespace. It's better to avoid sending headers with blank values by adding a check like!this.requestReason.trim().isEmpty()."x-goog-request-reason"is also used in the test file. Defining it as a public constant inBigQueryJdbcUrlUtilitywould avoid magic strings and improve maintainability.Here's a suggested implementation that applies the first point: