diff --git a/crates/cli/.gitignore b/crates/cli/.gitignore new file mode 100644 index 0000000..301bfb4 --- /dev/null +++ b/crates/cli/.gitignore @@ -0,0 +1 @@ +Superfile.hcl \ No newline at end of file diff --git a/crates/cli/src/config.rs b/crates/cli/src/config.rs index 991ab1e..aafa5ae 100644 --- a/crates/cli/src/config.rs +++ b/crates/cli/src/config.rs @@ -24,3 +24,35 @@ pub fn verify_if_config_file_is_present() -> Result<(String, String), Error> { let config = std::fs::read_to_string(current_dir.join(SUPERFILE_TOML))?; return Ok((config, String::from("toml"))); } + +#[cfg(test)] +pub mod tests { + use super::*; + + pub const CONFIG_EXAMPLE: &str = r#" + project = "demo" + + service "demo" { + type = "exec" + command = "ping $GITHUB_DOMAIN" + working_dir = "/tmp" + description = "Ping Service Example" + depends_on = [] + env = { + "GITHUB_DOMAIN" = "github.com" + } + stdout = "/tmp/demo-stdout.log" + stderr = "/tmp/demo-stderr.log" + } + "#; + + #[test] + fn test_verify_if_config_file_is_present() { + // create a default config file + let current_dir = std::env::current_dir().unwrap(); + let config_file = current_dir.join(SUPERFILE); + std::fs::write(config_file, CONFIG_EXAMPLE).unwrap(); + let result = verify_if_config_file_is_present(); + assert!(result.is_ok()); + } +} diff --git a/crates/util/src/lib.rs b/crates/util/src/lib.rs index bd79219..663988d 100644 --- a/crates/util/src/lib.rs +++ b/crates/util/src/lib.rs @@ -31,3 +31,21 @@ pub fn read_lines(path: &str) -> Result, Error> { } Ok(lines) } + +#[cfg(test)] +pub mod tests { + #[test] + fn convert_dir_path_to_absolute_path() { + let current_dir = std::env::current_dir().unwrap(); + let current_dir = current_dir.to_str().unwrap(); + let dir = "./test"; + let dir = super::convert_dir_path_to_absolute_path(dir, current_dir).unwrap(); + assert_eq!(dir, format!("{}/test", current_dir)); + } + + #[test] + fn read_lines() { + let lines = super::read_lines("Cargo.toml").unwrap(); + assert_eq!(lines[0], "[package]"); + } +}