mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
test/chown: use wheel group on BSD
This commit is contained in:
parent
9d03a80de8
commit
ce90685e8a
1 changed files with 20 additions and 46 deletions
|
|
@ -36,6 +36,11 @@ fn skipping_test_is_okay(result: &CmdResult, needle: &str) -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android", target_os = "windows"))]
|
||||
const ROOT_GROUP: &str = "root";
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "windows")))]
|
||||
const ROOT_GROUP: &str = "wheel";
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_passgrp {
|
||||
use chown::entries::{gid2grp, grp2gid, uid2usr, usr2uid};
|
||||
|
|
@ -49,11 +54,7 @@ mod test_passgrp {
|
|||
|
||||
#[test]
|
||||
fn test_grp2gid() {
|
||||
if cfg!(target_os = "linux") || cfg!(target_os = "android") || cfg!(target_os = "windows") {
|
||||
assert_eq!(0, grp2gid("root").unwrap());
|
||||
} else {
|
||||
assert_eq!(0, grp2gid("wheel").unwrap());
|
||||
}
|
||||
assert_eq!(0, grp2gid(super::ROOT_GROUP).unwrap());
|
||||
assert!(grp2gid("88_888_888").is_err());
|
||||
assert!(grp2gid("agroupthatdoesntexist").is_err());
|
||||
}
|
||||
|
|
@ -66,11 +67,7 @@ mod test_passgrp {
|
|||
|
||||
#[test]
|
||||
fn test_gid2grp() {
|
||||
if cfg!(target_os = "linux") || cfg!(target_os = "android") || cfg!(target_os = "windows") {
|
||||
assert_eq!("root", gid2grp(0).unwrap());
|
||||
} else {
|
||||
assert_eq!("wheel", gid2grp(0).unwrap());
|
||||
}
|
||||
assert_eq!(super::ROOT_GROUP, gid2grp(0).unwrap());
|
||||
assert!(gid2grp(88_888_888).is_err());
|
||||
}
|
||||
}
|
||||
|
|
@ -218,8 +215,7 @@ fn test_chown_failed_stdout() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
// FixME: Fails on freebsd because of chown: invalid group: 'root:root'
|
||||
#[cfg(all(not(target_os = "freebsd"), not(target_os = "openbsd")))]
|
||||
#[cfg(not(target_os = "openbsd"))]
|
||||
fn test_chown_owner_group() {
|
||||
// test chown username:group file.txt
|
||||
|
||||
|
|
@ -271,11 +267,9 @@ fn test_chown_owner_group() {
|
|||
.fails()
|
||||
.stderr_contains("invalid group");
|
||||
|
||||
// TODO: on macos group name is not recognized correctly: "chown: invalid group: 'root:root'
|
||||
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("root:root")
|
||||
.arg(format!("root:{ROOT_GROUP}"))
|
||||
.arg("--verbose")
|
||||
.arg(file1)
|
||||
.fails()
|
||||
|
|
@ -283,8 +277,7 @@ fn test_chown_owner_group() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
// FixME: Fails on freebsd because of chown: invalid group: 'root:root'
|
||||
#[cfg(all(not(target_os = "freebsd"), not(target_os = "openbsd")))]
|
||||
#[cfg(not(target_os = "openbsd"))]
|
||||
fn test_chown_various_input() {
|
||||
// test chown username:group file.txt
|
||||
|
||||
|
|
@ -344,50 +337,35 @@ fn test_chown_various_input() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
// FixME: on macos & freebsd group name is not recognized correctly: "chown: invalid group: ':groupname'
|
||||
#[cfg(any(
|
||||
windows,
|
||||
all(
|
||||
unix,
|
||||
not(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))
|
||||
)
|
||||
))]
|
||||
#[cfg(any(windows, all(unix, not(target_os = "openbsd"))))]
|
||||
fn test_chown_only_group() {
|
||||
// test chown :group file.txt
|
||||
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let result = scene.cmd("whoami").run();
|
||||
if skipping_test_is_okay(&result, "whoami: cannot find name for user ID") {
|
||||
let result = scene.cmd("id").arg("-gn").run();
|
||||
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
|
||||
return;
|
||||
}
|
||||
let user_name = String::from(result.stdout_str().trim());
|
||||
assert!(!user_name.is_empty());
|
||||
let group_name = String::from(result.stdout_str().trim());
|
||||
assert!(!group_name.is_empty());
|
||||
|
||||
let file1 = "test_chown_file1";
|
||||
at.touch(file1);
|
||||
|
||||
let result = scene
|
||||
.ucmd()
|
||||
.arg(format!(":{user_name}"))
|
||||
.arg(format!(":{group_name}"))
|
||||
.arg("--verbose")
|
||||
.arg(file1)
|
||||
.run();
|
||||
if is_ci() && result.stderr_str().contains("Operation not permitted") {
|
||||
// With ubuntu with old Rust in the CI, we can get an error
|
||||
return;
|
||||
}
|
||||
if is_ci() && result.stderr_str().contains("chown: invalid group:") {
|
||||
// With mac into the CI, we can get this answer
|
||||
return;
|
||||
}
|
||||
result.stderr_contains("retained as");
|
||||
result.success();
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(":root")
|
||||
.arg(format!(":{ROOT_GROUP}"))
|
||||
.arg("--verbose")
|
||||
.arg(file1)
|
||||
.fails()
|
||||
|
|
@ -484,8 +462,7 @@ fn test_chown_only_user_id_nonexistent_user() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
// FixME: stderr = chown: ownership of 'test_chown_file1' retained as cuuser:wheel
|
||||
#[cfg(all(not(target_os = "freebsd"), not(target_os = "openbsd")))]
|
||||
#[cfg(not(target_os = "openbsd"))]
|
||||
fn test_chown_only_group_id() {
|
||||
// test chown :1111 file.txt
|
||||
|
||||
|
|
@ -610,8 +587,7 @@ fn test_chown_owner_group_id() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
// FixME: Fails on freebsd because of chown: invalid group: '0:root'
|
||||
#[cfg(all(not(target_os = "freebsd"), not(target_os = "openbsd")))]
|
||||
#[cfg(not(target_os = "openbsd"))]
|
||||
fn test_chown_owner_group_mix() {
|
||||
// test chown 1111:group file.txt
|
||||
|
||||
|
|
@ -643,11 +619,9 @@ fn test_chown_owner_group_mix() {
|
|||
.run();
|
||||
result.stderr_contains("retained as");
|
||||
|
||||
// TODO: on macos group name is not recognized correctly: "chown: invalid group: '0:root'
|
||||
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("0:root")
|
||||
.arg(format!("0:{ROOT_GROUP}"))
|
||||
.arg("--verbose")
|
||||
.arg(file1)
|
||||
.fails()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue