1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #5168 from cakebaker/chown_remove_duplication_in_tests

chown: remove some duplication in tests
This commit is contained in:
Sylvestre Ledru 2023-08-21 12:22:32 +02:00 committed by GitHub
commit d8f28364f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -748,7 +748,7 @@ fn test_chown_file_notexisting() {
} }
#[test] #[test]
fn test_chown_no_change_to_user_from_user() { fn test_chown_no_change_to_user() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let at = &scene.fixtures; let at = &scene.fixtures;
@ -759,20 +759,22 @@ fn test_chown_no_change_to_user_from_user() {
let user_name = String::from(result.stdout_str().trim()); let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty()); assert!(!user_name.is_empty());
let file = "f"; for (i, from) in ["42", ":42", "42:42"].iter().enumerate() {
at.touch(file); let file = i.to_string();
at.touch(&file);
scene scene
.ucmd() .ucmd()
.arg("-v") .arg("-v")
.arg("--from=42") .arg(format!("--from={from}"))
.arg("43") .arg("43")
.arg(file) .arg(&file)
.succeeds() .succeeds()
.stdout_only(format!("ownership of '{file}' retained as {user_name}\n")); .stdout_only(format!("ownership of '{file}' retained as {user_name}\n"));
}
} }
#[test] #[test]
fn test_chown_no_change_to_user_from_group() { fn test_chown_no_change_to_group() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let at = &scene.fixtures; let at = &scene.fixtures;
@ -782,55 +784,6 @@ fn test_chown_no_change_to_user_from_group() {
} }
let user_name = String::from(result.stdout_str().trim()); let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty()); assert!(!user_name.is_empty());
let file = "f";
at.touch(file);
scene
.ucmd()
.arg("-v")
.arg("--from=:42")
.arg("43")
.arg(file)
.succeeds()
.stdout_only(format!("ownership of '{file}' retained as {user_name}\n"));
}
#[test]
fn test_chown_no_change_to_user_from_user_group() {
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") {
return;
}
let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty());
let file = "f";
at.touch(file);
scene
.ucmd()
.arg("-v")
.arg("--from=42:42")
.arg("43")
.arg(file)
.succeeds()
.stdout_only(format!("ownership of '{file}' retained as {user_name}\n"));
}
#[test]
fn test_chown_no_change_to_group_from_user() {
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") {
return;
}
let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty());
let result = scene.cmd("id").arg("-ng").run(); let result = scene.cmd("id").arg("-ng").run();
if skipping_test_is_okay(&result, "id: cannot find name for group ID") { if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
return; return;
@ -838,20 +791,22 @@ fn test_chown_no_change_to_group_from_user() {
let group_name = String::from(result.stdout_str().trim()); let group_name = String::from(result.stdout_str().trim());
assert!(!group_name.is_empty()); assert!(!group_name.is_empty());
let file = "f"; for (i, from) in ["42", ":42", "42:42"].iter().enumerate() {
at.touch(file); let file = i.to_string();
at.touch(&file);
scene scene
.ucmd() .ucmd()
.arg("-v") .arg("-v")
.arg("--from=42") .arg(format!("--from={from}"))
.arg(":43") .arg(":43")
.arg(file) .arg(&file)
.succeeds() .succeeds()
.stdout_only(format!("ownership of '{file}' retained as {group_name}\n")); .stdout_only(format!("ownership of '{file}' retained as {group_name}\n"));
}
} }
#[test] #[test]
fn test_chown_no_change_to_group_from_group() { fn test_chown_no_change_to_user_group() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let at = &scene.fixtures; let at = &scene.fixtures;
@ -868,141 +823,18 @@ fn test_chown_no_change_to_group_from_group() {
let group_name = String::from(result.stdout_str().trim()); let group_name = String::from(result.stdout_str().trim());
assert!(!group_name.is_empty()); assert!(!group_name.is_empty());
let file = "f"; for (i, from) in ["42", ":42", "42:42"].iter().enumerate() {
at.touch(file); let file = i.to_string();
at.touch(&file);
scene scene
.ucmd() .ucmd()
.arg("-v") .arg("-v")
.arg("--from=:42") .arg(format!("--from={from}"))
.arg(":43")
.arg(file)
.succeeds()
.stdout_only(format!("ownership of '{file}' retained as {group_name}\n"));
}
#[test]
fn test_chown_no_change_to_group_from_user_group() {
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") {
return;
}
let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty());
let result = scene.cmd("id").arg("-ng").run();
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
return;
}
let group_name = String::from(result.stdout_str().trim());
assert!(!group_name.is_empty());
let file = "f";
at.touch(file);
scene
.ucmd()
.arg("-v")
.arg("--from=42:42")
.arg(":43")
.arg(file)
.succeeds()
.stdout_only(format!("ownership of '{file}' retained as {group_name}\n"));
}
#[test]
fn test_chown_no_change_to_user_group_from_user() {
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") {
return;
}
let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty());
let result = scene.cmd("id").arg("-ng").run();
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
return;
}
let group_name = String::from(result.stdout_str().trim());
assert!(!group_name.is_empty());
let file = "f";
at.touch(file);
scene
.ucmd()
.arg("-v")
.arg("--from=42")
.arg("43:43") .arg("43:43")
.arg(file) .arg(&file)
.succeeds()
.stdout_only(format!(
"ownership of '{file}' retained as {user_name}:{group_name}\n"
));
}
#[test]
fn test_chown_no_change_to_user_group_from_group() {
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") {
return;
}
let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty());
let result = scene.cmd("id").arg("-ng").run();
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
return;
}
let group_name = String::from(result.stdout_str().trim());
assert!(!group_name.is_empty());
let file = "f";
at.touch(file);
scene
.ucmd()
.arg("-v")
.arg("--from=:42")
.arg("43:43")
.arg(file)
.succeeds()
.stdout_only(format!(
"ownership of '{file}' retained as {user_name}:{group_name}\n"
));
}
#[test]
fn test_chown_no_change_to_user_group_from_user_group() {
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") {
return;
}
let user_name = String::from(result.stdout_str().trim());
assert!(!user_name.is_empty());
let result = scene.cmd("id").arg("-ng").run();
if skipping_test_is_okay(&result, "id: cannot find name for group ID") {
return;
}
let group_name = String::from(result.stdout_str().trim());
assert!(!group_name.is_empty());
let file = "f";
at.touch(file);
scene
.ucmd()
.arg("-v")
.arg("--from=42:42")
.arg("43:43")
.arg(file)
.succeeds() .succeeds()
.stdout_only(format!( .stdout_only(format!(
"ownership of '{file}' retained as {user_name}:{group_name}\n" "ownership of '{file}' retained as {user_name}:{group_name}\n"
)); ));
}
} }