#![allow(unused_imports)]
use super::check::*;
use super::check_test_runners::RunnerOpts;
use super::dispatch_notify::*;
use super::dispatch_notify_custom::*;
use super::doctor::*;
use super::secrets::*;
use super::test_fixtures::*;
use std::path::Path;
#[cfg(test)]
mod tests {
use super::*;
fn write_check_config(dir: &std::path::Path) -> std::path::PathBuf {
let file = dir.join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: check-test
machines:
local:
hostname: localhost
addr: 127.0.0.1
resources:
pkg1:
type: package
machine: local
name: coreutils
tags: [base, system]
cfg1:
type: file
machine: local
path: /tmp/forjar-check-test.txt
content: "hello"
tags: [config]
"#,
)
.unwrap();
file
}
#[test]
fn test_cmd_doctor_with_fix_flag() {
let result = cmd_doctor(None, false, true);
assert!(result.is_ok());
}
#[test]
fn test_cmd_doctor_json_with_fix() {
let result = cmd_doctor(None, true, true);
assert!(result.is_ok());
}
#[test]
fn test_cmd_doctor_with_enc_markers_config() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: enc-test
machines:
local:
hostname: localhost
addr: 127.0.0.1
resources:
secret:
type: file
machine: local
path: /tmp/secret.txt
content: "ENC[age,fakeciphertext]"
"#,
)
.unwrap();
let _ = cmd_doctor(Some(&file), false, false);
}
#[test]
fn test_cmd_doctor_with_enc_markers_config_json() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: enc-test
machines:
local:
hostname: localhost
addr: 127.0.0.1
resources:
secret:
type: file
machine: local
path: /tmp/secret.txt
content: "ENC[age,fakeciphertext]"
"#,
)
.unwrap();
let _ = cmd_doctor(Some(&file), true, false);
}
#[test]
fn test_cmd_doctor_with_container_config_json() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: ctr-test
machines:
ctr:
hostname: ctr
addr: container
transport: container
container:
image: alpine:3.18
runtime: podman
resources:
f:
type: file
machine: ctr
path: /tmp/test
content: "x"
"#,
)
.unwrap();
let _ = cmd_doctor(Some(&file), true, false);
}
#[test]
fn test_cmd_doctor_with_container_default_runtime() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: ctr-test
machines:
ctr:
hostname: ctr
addr: container
transport: container
resources:
f:
type: file
machine: ctr
path: /tmp/test
content: "x"
"#,
)
.unwrap();
let _ = cmd_doctor(Some(&file), false, false);
}
#[test]
fn test_cmd_doctor_network_no_file_default_path() {
let result = cmd_doctor_network(None, false);
let _ = result;
}
#[test]
fn test_cmd_doctor_network_local_only() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: net-test
machines:
local:
hostname: localhost
addr: 127.0.0.1
resources:
f:
type: file
machine: local
path: /tmp/test
content: "x"
"#,
)
.unwrap();
let result = cmd_doctor_network(Some(&file), false);
assert!(result.is_ok());
}
#[test]
fn test_cmd_doctor_network_local_only_json() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: net-test
machines:
local:
hostname: localhost
addr: 127.0.0.1
resources:
f:
type: file
machine: local
path: /tmp/test
content: "x"
"#,
)
.unwrap();
let result = cmd_doctor_network(Some(&file), true);
assert!(result.is_ok());
}
#[test]
fn test_cmd_doctor_network_with_ssh_key() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: net-test
machines:
remote:
hostname: remote
addr: 10.0.0.99
user: deploy
ssh_key: /nonexistent/key.pem
resources:
f:
type: file
machine: remote
path: /tmp/test
content: "x"
"#,
)
.unwrap();
let result = cmd_doctor_network(Some(&file), false);
assert!(result.is_ok());
}
#[test]
fn test_cmd_doctor_network_with_ssh_key_json() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: net-test
machines:
remote:
hostname: remote
addr: 10.0.0.99
user: deploy
ssh_key: /nonexistent/key.pem
resources:
f:
type: file
machine: remote
path: /tmp/test
content: "x"
"#,
)
.unwrap();
let result = cmd_doctor_network(Some(&file), true);
assert!(result.is_ok());
}
#[test]
fn test_cmd_doctor_network_localhost_alias() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(
&file,
r#"
version: "1.0"
name: net-test
machines:
lo:
hostname: lo
addr: localhost
resources:
f:
type: file
machine: lo
path: /tmp/test
content: "x"
"#,
)
.unwrap();
let result = cmd_doctor_network(Some(&file), false);
assert!(result.is_ok());
}
#[test]
fn test_cmd_doctor_network_invalid_config() {
let dir = tempfile::tempdir().unwrap();
let file = dir.path().join("forjar.yaml");
std::fs::write(&file, "invalid: [[[").unwrap();
let result = cmd_doctor_network(Some(&file), false);
assert!(result.is_err());
}
#[test]
fn test_cmd_test_combined_machine_and_tag_filter() {
let dir = tempfile::tempdir().unwrap();
let config = write_check_config(dir.path());
let _ = cmd_test(
&config,
Some("local"),
None,
Some("system"),
None,
false,
false,
&RunnerOpts::default(),
);
}
#[test]
fn test_cmd_test_json_with_group_filter() {
let dir = tempfile::tempdir().unwrap();
let config = write_check_config(dir.path());
let _ = cmd_test(&config, None, None, None, Some("nonexistent"), true, false, &RunnerOpts::default());
}
#[test]
fn test_cmd_test_verbose_json() {
let dir = tempfile::tempdir().unwrap();
let config = write_check_config(dir.path());
let _ = cmd_test(&config, None, None, None, None, true, true, &RunnerOpts::default());
}
}