diff --git a/rust/samples/sample.conf b/rust/samples/sample.conf index b2eee5e..d7a3beb 100644 --- a/rust/samples/sample.conf +++ b/rust/samples/sample.conf @@ -10,4 +10,4 @@ plan = "free" version = "11" [redis] -plan = "free" +plan = "free" \ No newline at end of file diff --git a/rust/src/iaas/config.rs b/rust/src/iaas/config.rs index 818c7d0..3278b81 100644 --- a/rust/src/iaas/config.rs +++ b/rust/src/iaas/config.rs @@ -1,4 +1,5 @@ #![allow(unused)] +use anyhow::Error; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; use serde::Deserialize; @@ -33,13 +34,14 @@ impl Conf { } } - pub fn read_configuration_file() -> Self { + pub fn read_configuration_file() -> Result { let conf_path = "./samples/sample.conf"; let contents = fs::read_to_string(conf_path) - .expect(format!("Unable to read <{conf_path:?}>").as_str()); + .expect(format!("Unable to read configuration: <{conf_path:?}>").as_str()); // Parse config. file. - let mut config: Conf = toml::from_str(&contents).expect("Unable to parse config. file!"); + let mut config: Conf = toml::from_str(&contents) + .expect(format!("Unable to parse configuration: <{conf_path:?}>").as_str()); // Populate any /"" fields. Self::populate_blank_values(&mut config); @@ -49,9 +51,9 @@ impl Conf { /////////////////////// // println!("[DEBUG] -> {:?}", config); - Self { + Ok(Self { database: config.database, redis: config.redis, - } + }) } -} +} \ No newline at end of file diff --git a/rust/src/main.rs b/rust/src/main.rs index 8b6b5f2..d204e74 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -25,7 +25,7 @@ async fn main() { //////////////////////////////////////////////// /// /// 2. Using simple .conf files for resource provisioning - let config = config::Conf::read_configuration_file(); + let config = config::Conf::read_configuration_file().unwrap(); println!("{:?}", config); } @@ -64,6 +64,9 @@ async fn main() { mod tests { use super::*; + /////////////////////// + // Service Management. + //////////////////////// #[tokio::test] async fn test_list_all_services() { let result = ServiceManager::list_all_services("10").await; @@ -108,4 +111,13 @@ mod tests { let services = result.unwrap(); assert!(!services.is_empty()); } + + ///////////////////////////////// + // Configuration Initialization. + //////////////////////////////// + #[test] + fn test_read_configuration_file() { + let config = config::Conf::read_configuration_file(); + assert!(config.is_ok()); + } }