Files
env-guard/tests/cli_test.rs
CI Bot fc90e05ebb
Some checks failed
CI / test (push) Failing after 9s
CI / binary (push) Has been skipped
CI / release (push) Has been skipped
Initial commit: env-guard CLI tool with CI/CD
2026-02-06 10:01:25 +00:00

67 lines
2.1 KiB
Rust

#[cfg(test)]
mod cli_tests {
use assert_cmd::Command;
use std::fs;
#[test]
fn test_cli_help() {
let mut cmd = Command::cargo_bin("env-guard").unwrap();
cmd.arg("--help").assert().success();
}
#[test]
fn test_cli_version() {
let mut cmd = Command::cargo_bin("env-guard").unwrap();
cmd.arg("--version").assert().success();
}
#[test]
fn test_cli_validate_missing_file() {
let mut cmd = Command::cargo_bin("env-guard").unwrap();
cmd.arg("validate").arg("--path").arg("nonexistent.env").assert().failure();
}
#[test]
fn test_cli_generate_missing_file() {
let mut cmd = Command::cargo_bin("env-guard").unwrap();
cmd.arg("generate").arg("--path").arg("nonexistent.env").assert().failure();
}
#[test]
fn test_cli_check_missing_file() {
let mut cmd = Command::cargo_bin("env-guard").unwrap();
cmd.arg("check").arg("--path").arg("nonexistent.env").assert().failure();
}
#[test]
fn test_cli_validate_command() {
let test_dir = "test_validate_dir";
fs::create_dir_all(test_dir).unwrap();
fs::write(format!("{}/.env", test_dir), "DATABASE_URL=postgres://localhost/db\nSECRET_KEY=secret").unwrap();
let mut cmd = Command::cargo_bin("env-guard").unwrap();
cmd.arg("validate").arg("--path").arg(format!("{}/.env", test_dir)).assert().success();
fs::remove_dir_all(test_dir).ok();
}
#[test]
fn test_cli_generate_command() {
let test_dir = "test_generate_dir";
fs::create_dir_all(test_dir).unwrap();
fs::write(format!("{}/.env", test_dir), "DATABASE_URL=postgres://localhost/db\nSECRET_KEY=secret").unwrap();
let mut cmd = Command::cargo_bin("env-guard").unwrap();
cmd.arg("generate")
.arg("--path")
.arg(format!("{}/.env", test_dir))
.arg("--output")
.arg(format!("{}/.env.example", test_dir))
.assert().success();
assert!(fs::read_to_string(format!("{}/.env.example", test_dir)).unwrap().contains("DATABASE_URL"));
fs::remove_dir_all(test_dir).ok();
}
}