Skip to content

Commit

Permalink
Added <config> test
Browse files Browse the repository at this point in the history
  • Loading branch information
irfanghat committed Jul 12, 2024
1 parent 4569ad3 commit 1b7cd0b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rust/samples/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ plan = "free"
version = "11"

[redis]
plan = "free"
plan = "free"
14 changes: 8 additions & 6 deletions rust/src/iaas/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(unused)]
use anyhow::Error;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use serde::Deserialize;
Expand Down Expand Up @@ -33,13 +34,14 @@ impl Conf {
}
}

pub fn read_configuration_file() -> Self {
pub fn read_configuration_file() -> Result<Self, Error> {
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 <black>/"" fields.
Self::populate_blank_values(&mut config);
Expand All @@ -49,9 +51,9 @@ impl Conf {
///////////////////////
// println!("[DEBUG] -> {:?}", config);

Self {
Ok(Self {
database: config.database,
redis: config.redis,
}
})
}
}
}
14 changes: 13 additions & 1 deletion rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 1b7cd0b

Please sign in to comment.