diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2023-05-10 17:55:34 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2023-05-10 17:55:34 +0200 |
commit | 08556b95edf02b8fde068d2db215c63446479564 (patch) | |
tree | c6e413e66cd4959ec35b2ecf28b9002bd7cca5d3 /user-info/src/lib.rs | |
parent | 447176eb86f88139f9974b789c03444245835874 (diff) |
Simplify project by getting rid of workspacev0.1.0
Diffstat (limited to 'user-info/src/lib.rs')
-rw-r--r-- | user-info/src/lib.rs | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/user-info/src/lib.rs b/user-info/src/lib.rs deleted file mode 100644 index 7a42db9..0000000 --- a/user-info/src/lib.rs +++ /dev/null @@ -1,37 +0,0 @@ -use nix::unistd::{getgroups, getuid, Group, User}; - -pub fn get_username() -> Option<String> { - let uid = getuid(); - User::from_uid(uid).ok().flatten().map(|user| user.name) -} - -pub fn get_user_groups() -> Vec<String> { - let gids = getgroups().unwrap_or(Vec::default()); - gids.into_iter() - .filter_map(|gid| Group::from_gid(gid).ok().flatten()) - .map(|group| group.name) - .collect() -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn it_returns_a_username() { - // We can't get too specific here because this is your actual username, - // but we at lease expect it to be some string, not None. - let username = get_username(); - let username_len = username.unwrap().trim().len(); - assert!(username_len > 0); - } - - #[test] - fn it_returns_some_groups() { - let groups = get_user_groups(); - assert!(groups.len() > 0); - for group in groups { - assert!(group.trim().len() > 0); - } - } -} |