1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![recursion_limit = "512"]

pub mod errors;
pub mod interface;
mod death_causes;
pub mod implementation;
mod service;
pub mod config;

pub mod lib {
    use super::{
        service::LogParser,
        implementation::log_parser::ConcreteLogParser,
    };

    pub fn factory() -> LogParser {
        let concrete_log_parser = ConcreteLogParser::new();
        let log_parser_service = LogParser::new(Box::new(concrete_log_parser));
        return log_parser_service;
    }

}

#[cfg(test)]
mod tests {

    use tokio::test;

    use super::{
        service::LogParser,
        implementation::log_parser::{ConcreteLogParser},
        config::{
            config::ConfigValue,
            dynamic_config::{CONFIG_FILE_PATH, CONFIG, ConfigParameter}
        }
    };

    #[test]
    async fn test() {

        CONFIG_FILE_PATH.with(|config_file_path_handler| {
            *config_file_path_handler.borrow_mut() = Some(String::from("config.json"));
        });

        CONFIG.with(|config| {
            config.borrow_mut().set_parameter(ConfigParameter::LogFilePath, ConfigValue::Str(String::from("sample_log.log")))
        });

        let concrete_log_parser = ConcreteLogParser::new();
        let mut log_parser_service = LogParser::new(Box::new(concrete_log_parser));
        if let Ok(value) = log_parser_service.parse_file().await {
            println!("{}", value);
        } else {
            println!("Error Parsing Log File");
        }
        
    }

}