use super::client::Subscriber;
use crate::ClientBuilderResult as BuilderResult;
use gaxi::options::ClientConfig;
use google_cloud_auth::credentials::Credentials;
const MAX_INBOUND_METADATA_SIZE: u32 = 4 * 1024 * 1024;
pub struct ClientBuilder {
pub(super) config: ClientConfig,
}
impl ClientBuilder {
pub(super) fn new() -> Self {
let mut config = ClientConfig::default();
config.grpc_max_header_list_size = Some(MAX_INBOUND_METADATA_SIZE);
Self { config }
}
pub async fn build(self) -> BuilderResult<Subscriber> {
Subscriber::new(self).await
}
pub fn with_endpoint<V: Into<String>>(mut self, v: V) -> Self {
self.config.endpoint = Some(v.into());
self
}
pub fn with_credentials<V: Into<Credentials>>(mut self, v: V) -> Self {
self.config.cred = Some(v.into());
self
}
pub fn with_grpc_subchannel_count(mut self, v: usize) -> Self {
self.config.grpc_subchannel_count = Some(v);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use google_cloud_auth::credentials::anonymous::Builder as Anonymous;
#[test]
fn defaults() {
let builder = ClientBuilder::new();
assert!(builder.config.endpoint.is_none(), "{:?}", builder.config);
assert!(builder.config.cred.is_none(), "{:?}", builder.config);
assert!(
builder.config.grpc_subchannel_count.is_none(),
"{:?}",
builder.config
);
assert_eq!(
builder.config.grpc_max_header_list_size,
Some(MAX_INBOUND_METADATA_SIZE)
);
}
#[test]
fn setters() {
let builder = ClientBuilder::new()
.with_endpoint("test-endpoint.com")
.with_credentials(Anonymous::new().build())
.with_grpc_subchannel_count(16);
assert_eq!(
builder.config.endpoint,
Some("test-endpoint.com".to_string())
);
assert!(builder.config.cred.is_some(), "{:?}", builder.config);
assert_eq!(builder.config.grpc_subchannel_count, Some(16));
}
}