1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

tests: disable some chgrp tests when part of the root group

Some tests failed when run using Docker because they assumed the
user would never be root.  This is more of a band-aid solution.
An actual fix would be to test see if something like these tests
were to succeed when the user is root.
This commit is contained in:
Alex Lyon 2018-03-01 23:08:09 -08:00
parent 8ece01d0ef
commit d8e738c49b
5 changed files with 298 additions and 249 deletions

View file

@ -1,5 +1,5 @@
use common::util::*;
use rust_users::*;
#[test]
fn test_invalid_option() {
@ -14,30 +14,34 @@ static DIR: &'static str = "/tmp";
#[test]
fn test_invalid_group() {
new_ucmd!()
.arg("nosuchgroup")
.arg("__nosuchgroup__")
.arg("/")
.fails()
.stderr_is("chgrp: invalid group: nosuchgroup");
.stderr_is("chgrp: invalid group: __nosuchgroup__");
}
#[test]
fn test_1() {
new_ucmd!()
.arg("bin")
.arg(DIR)
.fails()
.stderr_is("chgrp: changing group of '/tmp': Operation not permitted (os error 1)");
if get_effective_gid() != 0 {
new_ucmd!()
.arg("bin")
.arg(DIR)
.fails()
.stderr_is("chgrp: changing group of '/tmp': Operation not permitted (os error 1)");
}
}
#[test]
fn test_fail_silently() {
for opt in &["-f", "--silent", "--quiet"] {
new_ucmd!()
.arg(opt)
.arg("bin")
.arg(DIR)
.run()
.fails_silently();
if get_effective_gid() != 0 {
for opt in &["-f", "--silent", "--quiet"] {
new_ucmd!()
.arg(opt)
.arg("bin")
.arg(DIR)
.run()
.fails_silently();
}
}
}
@ -94,13 +98,15 @@ fn test_preserve_root_symlink() {
#[test]
#[cfg(target_os = "linux")]
fn test_reference() {
new_ucmd!()
.arg("-v")
.arg("--reference=/etc/passwd")
.arg("/etc")
.fails()
.stderr_is("chgrp: changing group of '/etc': Operation not permitted (os error 1)\n")
.stdout_is("failed to change group of /etc from root to root\n");
if get_effective_gid() != 0 {
new_ucmd!()
.arg("-v")
.arg("--reference=/etc/passwd")
.arg("/etc")
.fails()
.stderr_is("chgrp: changing group of '/etc': Operation not permitted (os error 1)\n")
.stdout_is("failed to change group of /etc from root to root\n");
}
}
#[test]
@ -116,23 +122,27 @@ fn test_reference() {
#[test]
#[cfg(target_os = "linux")]
fn test_big_p() {
new_ucmd!()
.arg("-RP")
.arg("bin")
.arg("/proc/self/cwd")
.fails()
.stderr_is("chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n");
if get_effective_gid() != 0 {
new_ucmd!()
.arg("-RP")
.arg("bin")
.arg("/proc/self/cwd")
.fails()
.stderr_is("chgrp: changing group of '/proc/self/cwd': Operation not permitted (os error 1)\n");
}
}
#[test]
#[cfg(target_os = "linux")]
fn test_big_h() {
assert!(new_ucmd!()
.arg("-RH")
.arg("bin")
.arg("/proc/self/fd")
.fails()
.stderr
.lines()
.fold(0, |acc, _| acc + 1) > 1);
if get_effective_gid() != 0 {
assert!(new_ucmd!()
.arg("-RH")
.arg("bin")
.arg("/proc/self/fd")
.fails()
.stderr
.lines()
.fold(0, |acc, _| acc + 1) > 1);
}
}

View file

@ -4,6 +4,9 @@ mod common;
#[macro_use]
extern crate lazy_static;
#[cfg(unix)]
extern crate rust_users;
// For conditional compilation
macro_rules! unix_only {
($($fea:expr, $m:ident);+) => {