use std::path::PathBuf;
use super::*;
#[test]
fn chmod_renders_correctly() {
let action = FixAction::Chmod {
path: PathBuf::from("/var/log/app"),
mode_change: "o+x".into(),
};
assert_eq!(render_command(&action), "chmod o+x /var/log/app");
}
#[test]
fn chown_with_both_owner_and_group() {
let action = FixAction::Chown {
path: PathBuf::from("/path/file"),
owner: Some(1000),
group: Some(33),
};
assert_eq!(render_command(&action), "chown 1000:33 /path/file");
}
#[test]
fn chown_with_group_only() {
let action = FixAction::Chown {
path: PathBuf::from("/path"),
owner: None,
group: Some(33),
};
assert_eq!(render_command(&action), "chown :33 /path");
}
#[test]
fn chown_with_owner_only() {
let action = FixAction::Chown {
path: PathBuf::from("/path"),
owner: Some(1000),
group: None,
};
assert_eq!(render_command(&action), "chown 1000 /path");
}
#[test]
fn setacl_renders_correctly() {
let action = FixAction::SetAcl {
path: PathBuf::from("/var/log"),
entry: "u:33:r".into(),
};
assert_eq!(render_command(&action), "setfacl -m u:33:r /var/log");
}
#[test]
fn remount_renders_correctly() {
let action = FixAction::Remount {
mountpoint: PathBuf::from("/var"),
options: "rw".into(),
};
assert_eq!(render_command(&action), "mount -o remount,rw /var");
}
#[test]
fn chattr_renders_correctly() {
let action = FixAction::Chattr {
path: PathBuf::from("/var/data.txt"),
flags: "-i".into(),
};
assert_eq!(render_command(&action), "chattr -i /var/data.txt");
}
#[test]
fn path_with_spaces_is_quoted() {
let action = FixAction::Chmod {
path: PathBuf::from("/var/log/my app/file.log"),
mode_change: "o+r".into(),
};
assert_eq!(
render_command(&action),
"chmod o+r '/var/log/my app/file.log'"
);
}
#[test]
fn remount_exec_renders_correctly() {
let action = FixAction::Remount {
mountpoint: PathBuf::from("/tmp"),
options: "exec".into(),
};
assert_eq!(render_command(&action), "mount -o remount,exec /tmp");
}