Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
chore: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed May 23, 2023
1 parent 89f4be1 commit f6c0458
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Superfile.hcl
32 changes: 32 additions & 0 deletions crates/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
18 changes: 18 additions & 0 deletions crates/util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ pub fn read_lines(path: &str) -> Result<Vec<String>, 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]");
}
}

0 comments on commit f6c0458

Please sign in to comment.