quake_log_parser_lib/
lib.rs

1#![recursion_limit = "512"]
2
3pub mod errors;
4pub mod interface;
5mod death_causes;
6pub mod implementation;
7mod service;
8pub mod config;
9
10pub mod lib {
11    use super::{
12        service::LogParser,
13        implementation::log_parser::ConcreteLogParser,
14    };
15
16    pub fn factory() -> LogParser {
17        let concrete_log_parser = ConcreteLogParser::new();
18        let log_parser_service = LogParser::new(Box::new(concrete_log_parser));
19        return log_parser_service;
20    }
21
22}
23
24#[cfg(test)]
25mod tests {
26
27    use tokio::test;
28
29    use super::{
30        service::LogParser,
31        implementation::log_parser::{ConcreteLogParser},
32        config::{
33            config::ConfigValue,
34            dynamic_config::{CONFIG_FILE_PATH, CONFIG, ConfigParameter}
35        }
36    };
37
38    #[test]
39    async fn test() {
40
41        CONFIG_FILE_PATH.with(|config_file_path_handler| {
42            *config_file_path_handler.borrow_mut() = Some(String::from("config.json"));
43        });
44
45        CONFIG.with(|config| {
46            config.borrow_mut().set_parameter(ConfigParameter::LogFilePath, ConfigValue::Str(String::from("sample_log.log")))
47        });
48
49        let concrete_log_parser = ConcreteLogParser::new();
50        let mut log_parser_service = LogParser::new(Box::new(concrete_log_parser));
51        if let Ok(value) = log_parser_service.parse_file().await {
52            println!("{}", value);
53        } else {
54            println!("Error Parsing Log File");
55        }
56        
57    }
58
59}