Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/bigquery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ uuid.workspace = true

[dev-dependencies]
anyhow.workspace = true
httptest.workspace = true
mockall.workspace = true
test-case.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "test-util"] }
Expand Down
65 changes: 65 additions & 0 deletions src/bigquery/src/query/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ pub struct BigQuery {
project_id: Option<String>,
}

pub(super) mod info {
pub(crate) const NAME: &str = env!("CARGO_PKG_NAME");
pub(crate) const VERSION: &str = env!("CARGO_PKG_VERSION");
}

impl BigQuery {
/// Returns a new [`ClientBuilder`] for configuring and instantiating a [`BigQuery`] client.
///
Expand Down Expand Up @@ -111,6 +116,14 @@ impl BigQuery {
job_service_builder = job_service_builder.with_backoff_policy(backoff_policy);
job_service_builder =
job_service_builder.with_retry_throttler(builder.config.retry_throttler);

job_service_builder =
job_service_builder.with_extension(gaxi::api_header::XGoogApiClient {
name: info::NAME,
version: info::VERSION,
library_type: gaxi::api_header::GCCL,
});

let job_service = Arc::new(job_service_builder.build().await?);

Ok(BigQuery {
Expand Down Expand Up @@ -420,4 +433,56 @@ mod tests {
);
Ok(())
}

#[tokio::test]
async fn test_bigquery_calls_send_veneer_header_not_gapic() -> anyhow::Result<()> {
use httptest::{Expectation, Server, all_of, matchers::*, responders::*};
use serde_json::json;

let server = Server::run();
server.expect(
Expectation::matching(all_of![
request::method_path("GET", "/bigquery/v2/projects/test-proj/jobs/job_123"),
request::headers(contains((
"x-goog-api-client",
matches(format!("gccl/{}", env!("CARGO_PKG_VERSION"))),
))),
not(request::headers(contains((
"x-goog-api-client",
matches("gapic/"),
)))),
])
.respond_with(json_encoded(json!({
"jobReference": {
"projectId": "test-proj",
"jobId": "job_123"
},
"configuration": {
"query": {
"query": "SELECT 1"
}
},
"status": {
"state": "DONE"
}
}))),
);

let client = BigQuery::builder()
.with_endpoint(server.url_str(""))
.with_credentials(Anonymous::new().build())
.with_project_id("test-proj")
.build()
.await?;

let job_ref = JobReference::new().set_job_id("job_123");
let query = client.attach_job(job_ref).await?;
let metadata = query.metadata();
assert_eq!(
metadata.job_reference.as_ref().map(|j| j.job_id.as_str()),
Some("job_123")
);

Ok(())
}
}
Loading