use std::env::current_dir;
use std::fs;
use std::path::Path;
use std::process::Command;
fn setup_template_test() {
let dir = Path::new("templates");
if !dir.exists() {
fs::create_dir_all(dir).ok();
}
let content = r#"name: Test CI
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: echo test
"#;
fs::write("templates/node.yml", content).ok();
fs::write("templates/rust.yml", content).ok();
fs::write("templates/docker.yml", content).ok();
fs::write("templates/gitlab-node.yml", content).ok();
}
#[test]
fn test_init_template_creates_file() {
setup_template_test();
let output = Command::new("cargo")
.args(["run", "--", "--init", "--template", "node"])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
let result = String::from_utf8_lossy(&output.stdout);
assert!(result.contains("Created") || output.status.success());
fs::remove_file(".github/workflows/node.yml").ok();
}
#[test]
fn test_init_template_rust() {
setup_template_test();
let output = Command::new("cargo")
.args(["run", "--", "--init", "--template", "rust"])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
let result = String::from_utf8_lossy(&output.stdout);
assert!(result.contains("Created") || output.status.success());
fs::remove_file(".github/workflows/rust.yml").ok();
}
#[test]
fn test_init_template_unknown() {
setup_template_test();
let output = Command::new("cargo")
.args(["run", "--", "--init", "--template", "invalid"])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
assert!(!output.status.success());
}
#[test]
fn test_diff_branch_default() {
let output = Command::new("cargo")
.args(["run", "--", "--help"])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
let result = String::from_utf8_lossy(&output.stdout);
assert!(result.contains("--diff-branch"));
}
#[test]
fn test_help_shows_diff() {
let output = Command::new("cargo")
.args(["run", "--", "--help"])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
let result = String::from_utf8_lossy(&output.stdout);
assert!(result.contains("--diff"));
assert!(result.contains("--init"));
assert!(result.contains("--template"));
}
#[test]
fn test_quiet_mode() {
let output = Command::new("cargo")
.args(["run", "--", "--quiet", "tests/fixtures/github/valid.yml"])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
assert!(output.status.success() || !output.status.success());
}
#[test]
fn test_strict_mode() {
let output = Command::new("cargo")
.args(["run", "--", "--strict", "tests/fixtures/github/valid.yml"])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
assert!(output.status.success() || !output.status.success());
}
#[test]
fn test_json_format() {
let output = Command::new("cargo")
.args(["run", "--", "-f", "json", "tests/fixtures/github/valid.yml"])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
let result = String::from_utf8_lossy(&output.stdout);
assert!(result.starts_with("{") || result.contains("provider"));
}
#[test]
fn test_verbose_mode() {
let output = Command::new("cargo")
.args(["run", "--", "--verbose", "tests/fixtures/github/valid.yml"])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
let result = String::from_utf8_lossy(&output.stderr);
assert!(result.contains("Auditing") || result.contains("Checked"));
}
#[test]
fn test_no_pinning_flag() {
let output = Command::new("cargo")
.args([
"run",
"--",
"--no-pinning",
"tests/fixtures/github/valid.yml",
])
.current_dir(current_dir().unwrap())
.output()
.expect("Failed to run command");
assert!(output.status.success() || !output.status.success());
}