use std::sync::Arc;
use crate::cog::Cog;
use crate::config::{CogConfig, Config, GearboxAppConfig};
use crate::hub::Hub;
use crate::registry::CogRegistry;
pub struct TestHubBuilder {
registry: CogRegistry,
config: Config,
}
impl TestHubBuilder {
pub fn new() -> Self {
Self {
registry: CogRegistry::new(),
config: Config::default(),
}
}
pub fn with_app_config(mut self, app: GearboxAppConfig) -> Self {
self.config.set_app(app);
self
}
pub fn with_config<C: CogConfig + Clone + 'static>(self, config: C) -> Self {
self.config.insert(config);
self
}
pub fn with_service<T: Cog + 'static>(self, service: T) -> Self {
self.registry
.put(service)
.expect("failed to register test service");
self
}
pub fn build(self) -> Arc<Hub> {
Arc::new(Hub {
registry: self.registry,
config: self.config,
})
}
}
impl Default for TestHubBuilder {
fn default() -> Self {
Self::new()
}
}