mirror of
https://github.com/bartvdbraak/keyweave.git
synced 2025-04-28 07:11:21 +00:00
feat: added unit test for creating env file
This commit is contained in:
parent
b9656bf118
commit
33874f2d35
1 changed files with 30 additions and 0 deletions
30
src/main.rs
30
src/main.rs
|
@ -114,6 +114,36 @@ fn create_env_file(secrets: Vec<(String, String)>, output_file: &str) -> Result<
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::fs;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_create_env_file() -> Result<()> {
|
||||||
|
let test_secrets = vec![
|
||||||
|
("SECRET_KEY".to_string(), "secret_value1".to_string()),
|
||||||
|
("API_KEY".to_string(), "secret_value2".to_string()),
|
||||||
|
];
|
||||||
|
|
||||||
|
let test_file = "test_output.env";
|
||||||
|
create_env_file(test_secrets, test_file)?;
|
||||||
|
|
||||||
|
let file = fs::File::open(test_file)?;
|
||||||
|
let reader = io::BufReader::new(file);
|
||||||
|
let lines: Vec<String> = reader.lines().collect::<Result<_, _>>()?;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
lines,
|
||||||
|
vec!["SECRET_KEY=secret_value1", "API_KEY=secret_value2",]
|
||||||
|
);
|
||||||
|
|
||||||
|
fs::remove_file(test_file)?; // Clean up the test file
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let opts: Opts = Opts::parse();
|
let opts: Opts = Opts::parse();
|
||||||
|
|
Loading…
Reference in a new issue