openlark_core/testing/
fixtures.rs1use crate::config::Config;
6
7#[derive(Debug, Clone)]
20pub struct TestConfigBuilder {
21 app_id: String,
22 app_secret: String,
23 base_url: String,
24}
25
26impl TestConfigBuilder {
27 pub fn new() -> Self {
29 Self {
30 app_id: "test_app_id".to_string(),
31 app_secret: "test_app_secret".to_string(),
32 base_url: "https://open.feishu.cn".to_string(),
33 }
34 }
35
36 pub fn app_id(mut self, id: impl Into<String>) -> Self {
38 self.app_id = id.into();
39 self
40 }
41
42 pub fn app_secret(mut self, secret: impl Into<String>) -> Self {
44 self.app_secret = secret.into();
45 self
46 }
47
48 pub fn base_url(mut self, url: impl Into<String>) -> Self {
50 self.base_url = url.into();
51 self
52 }
53
54 pub fn build(self) -> Config {
56 Config::builder()
57 .app_id(self.app_id)
58 .app_secret(self.app_secret)
59 .base_url(self.base_url)
60 .build()
61 }
62}
63
64impl Default for TestConfigBuilder {
65 fn default() -> Self {
66 Self::new()
67 }
68}
69
70pub fn test_config() -> Config {
72 TestConfigBuilder::new().build()
73}
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
80 fn test_test_config_builder() {
81 let config = TestConfigBuilder::new()
82 .app_id("my_app")
83 .app_secret("my_secret")
84 .build();
85
86 assert_eq!(config.app_id(), "my_app");
87 assert_eq!(config.app_secret(), "my_secret");
88 }
89
90 #[test]
91 fn test_test_config_default() {
92 let config = test_config();
93 assert_eq!(config.app_id(), "test_app_id");
94 assert_eq!(config.app_secret(), "test_app_secret");
95 }
96}