use crate::config::Config;
#[derive(Debug, Clone)]
pub struct TestConfigBuilder {
app_id: String,
app_secret: String,
base_url: String,
}
impl TestConfigBuilder {
pub fn new() -> Self {
Self {
app_id: "test_app_id".to_string(),
app_secret: "test_app_secret".to_string(),
base_url: "https://open.feishu.cn".to_string(),
}
}
pub fn app_id(mut self, id: impl Into<String>) -> Self {
self.app_id = id.into();
self
}
pub fn app_secret(mut self, secret: impl Into<String>) -> Self {
self.app_secret = secret.into();
self
}
pub fn base_url(mut self, url: impl Into<String>) -> Self {
self.base_url = url.into();
self
}
pub fn build(self) -> Config {
Config::builder()
.app_id(self.app_id)
.app_secret(self.app_secret)
.base_url(self.base_url)
.build()
}
}
impl Default for TestConfigBuilder {
fn default() -> Self {
Self::new()
}
}
pub fn test_config() -> Config {
TestConfigBuilder::new().build()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_test_config_builder() {
let config = TestConfigBuilder::new()
.app_id("my_app")
.app_secret("my_secret")
.build();
assert_eq!(config.app_id(), "my_app");
assert_eq!(config.app_secret(), "my_secret");
}
#[test]
fn test_test_config_default() {
let config = test_config();
assert_eq!(config.app_id(), "test_app_id");
assert_eq!(config.app_secret(), "test_app_secret");
}
}