2016-06-22 13:39:46 +00:00
|
|
|
use common::util::*;
|
|
|
|
|
2020-05-04 06:25:36 +00:00
|
|
|
extern crate chown;
|
|
|
|
// pub use self::uu_chown::*;
|
2016-06-22 13:39:46 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
2016-08-14 05:22:42 +00:00
|
|
|
mod test_passgrp {
|
2020-05-04 06:25:36 +00:00
|
|
|
use super::chown::entries::{gid2grp, grp2gid, uid2usr, usr2uid};
|
2016-06-22 13:39:46 +00:00
|
|
|
|
|
|
|
#[test]
|
2016-08-14 05:22:42 +00:00
|
|
|
fn test_usr2uid() {
|
|
|
|
assert_eq!(0, usr2uid("root").unwrap());
|
|
|
|
assert!(usr2uid("88888888").is_err());
|
|
|
|
assert!(usr2uid("auserthatdoesntexist").is_err());
|
2016-06-22 13:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2016-08-14 05:22:42 +00:00
|
|
|
fn test_grp2gid() {
|
2019-04-28 02:14:22 +00:00
|
|
|
if cfg!(target_os = "linux") || cfg!(target_os = "android") || cfg!(target_os = "windows") {
|
|
|
|
assert_eq!(0, grp2gid("root").unwrap())
|
2016-07-04 14:50:54 +00:00
|
|
|
} else {
|
2019-04-28 02:14:22 +00:00
|
|
|
assert_eq!(0, grp2gid("wheel").unwrap());
|
2016-07-04 14:50:54 +00:00
|
|
|
}
|
2016-08-14 05:22:42 +00:00
|
|
|
assert!(grp2gid("88888888").is_err());
|
|
|
|
assert!(grp2gid("agroupthatdoesntexist").is_err());
|
2016-06-22 13:39:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_uid2usr() {
|
|
|
|
assert_eq!("root", uid2usr(0).unwrap());
|
|
|
|
assert!(uid2usr(88888888).is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_gid2grp() {
|
2019-04-28 02:14:22 +00:00
|
|
|
if cfg!(target_os = "linux") || cfg!(target_os = "android") || cfg!(target_os = "windows") {
|
2016-07-04 14:50:54 +00:00
|
|
|
assert_eq!("root", gid2grp(0).unwrap());
|
2019-04-28 02:14:22 +00:00
|
|
|
} else {
|
|
|
|
assert_eq!("wheel", gid2grp(0).unwrap());
|
2016-07-04 14:50:54 +00:00
|
|
|
}
|
2016-06-22 13:39:46 +00:00
|
|
|
assert!(gid2grp(88888888).is_err());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_invalid_option() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!().arg("-w").arg("-q").arg("/").fails();
|
2016-06-22 13:39:46 +00:00
|
|
|
}
|