aetheris_server/
config.rs1#[derive(Debug, Clone)]
7pub struct ServerConfig {
8 pub metrics_port: u16,
10 pub tick_rate: u64,
12}
13
14impl ServerConfig {
15 #[must_use]
17 pub fn load() -> Self {
18 let metrics_port = std::env::var("AETHERIS_METRICS_PORT")
19 .ok()
20 .and_then(|s| s.parse().ok())
21 .unwrap_or(9000);
22
23 let tick_rate = std::env::var("AETHERIS_TICK_RATE")
24 .ok()
25 .and_then(|s| s.parse().ok())
26 .unwrap_or(60);
27
28 Self {
29 metrics_port,
30 tick_rate,
31 }
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_config_defaults() {
41 unsafe {
43 std::env::remove_var("AETHERIS_METRICS_PORT");
44 }
45 let config = ServerConfig::load();
46 assert_eq!(config.metrics_port, 9000);
47 }
48
49 #[test]
50 fn test_config_env_override() {
51 unsafe {
52 std::env::set_var("AETHERIS_METRICS_PORT", "9500");
53 }
54 let config = ServerConfig::load();
55 assert_eq!(config.metrics_port, 9500);
56 unsafe {
57 std::env::remove_var("AETHERIS_METRICS_PORT");
58 }
59 }
60}