use crate::ClientBuilderResult as BuilderResult;
use crate::client::Write;
use gaxi::options::ClientConfig;
use google_cloud_auth::credentials::Credentials;
#[derive(Debug)]
pub struct ClientBuilder {
pub(super) config: ClientConfig,
}
impl ClientBuilder {
pub(super) fn new() -> Self {
Self {
config: ClientConfig::default(),
}
}
pub async fn build(self) -> BuilderResult<Write> {
Write::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_universe_domain<V: Into<String>>(mut self, v: V) -> Self {
self.config.universe_domain = 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.universe_domain.is_none(),
"{:?}",
builder.config
);
assert!(
builder.config.grpc_subchannel_count.is_none(),
"{:?}",
builder.config
);
}
#[test]
fn setters() {
let builder = ClientBuilder::new()
.with_endpoint("test-endpoint.com")
.with_universe_domain("test-ud.com")
.with_credentials(Anonymous::new().build())
.with_grpc_subchannel_count(16);
assert_eq!(
builder.config.endpoint,
Some("test-endpoint.com".to_string())
);
assert_eq!(
builder.config.universe_domain,
Some("test-ud.com".to_string())
);
assert!(builder.config.cred.is_some(), "{:?}", builder.config);
assert_eq!(builder.config.grpc_subchannel_count, Some(16));
}
}