1#[derive(Debug, Clone)]
2pub struct FunctionConfig {
3 pub default_timeout_ms: u64,
4 pub health_interval: std::time::Duration,
5 pub boot_timeout: std::time::Duration,
6}
7
8impl Default for FunctionConfig {
9 fn default() -> Self {
10 Self {
11 default_timeout_ms: 5000,
12 health_interval: std::time::Duration::from_secs(5),
13 boot_timeout: std::time::Duration::from_secs(10),
14 }
15 }
16}
17
18impl FunctionConfig {
19 pub fn validate(&self) -> Result<(), camel_api::CamelError> {
20 if self.default_timeout_ms == 0 {
21 return Err(camel_api::CamelError::Config(
22 "default_timeout_ms must be > 0".to_string(),
23 ));
24 }
25 if self.health_interval == std::time::Duration::ZERO {
26 return Err(camel_api::CamelError::Config(
27 "health_interval must be > 0".to_string(),
28 ));
29 }
30 if self.boot_timeout == std::time::Duration::ZERO {
31 return Err(camel_api::CamelError::Config(
32 "boot_timeout must be > 0".to_string(),
33 ));
34 }
35 Ok(())
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use super::*;
42
43 #[test]
44 fn test_config_valid_default() {
45 let config = FunctionConfig::default();
46 assert!(config.validate().is_ok());
47 }
48
49 #[test]
50 fn test_config_zero_timeout_rejected() {
51 let config = FunctionConfig {
52 default_timeout_ms: 0,
53 ..Default::default()
54 };
55 assert!(config.validate().is_err());
56 }
57
58 #[test]
59 fn test_config_zero_health_interval_rejected() {
60 let config = FunctionConfig {
61 health_interval: std::time::Duration::ZERO,
62 ..Default::default()
63 };
64 assert!(config.validate().is_err());
65 }
66
67 #[test]
68 fn test_config_zero_boot_timeout_rejected() {
69 let config = FunctionConfig {
70 boot_timeout: std::time::Duration::ZERO,
71 ..Default::default()
72 };
73 assert!(config.validate().is_err());
74 }
75}