Skip to content

Commit

Permalink
Add trivial tests for chown and fchownat
Browse files Browse the repository at this point in the history
These are mostly to ensure that all the platforms we care about in our
CI can reference these primitives.
  • Loading branch information
jmmv committed Oct 20, 2018
1 parent f3dab48 commit 9bf4ab3
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion test/test_unistd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use nix::fcntl::{fcntl, FcntlArg, FdFlag, OFlag};
use nix::fcntl::{fcntl, FcntlArg, FdFlag, open, OFlag};
use nix::unistd::*;
use nix::unistd::ForkResult::*;
use nix::sys::signal::{SaFlags, SigAction, SigHandler, SigSet, Signal, sigaction};
Expand Down Expand Up @@ -301,6 +301,49 @@ fn test_getcwd() {
assert_eq!(getcwd().unwrap(), inner_tmp_dir.as_path());
}

#[test]
fn test_chown() {
// Testing for anything other than our own UID/GID is hard.
let uid = Some(getuid());
let gid = Some(getgid());

let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path().join("file");
{
File::create(&path).unwrap();
}

chown(&path, uid, gid).unwrap();
chown(&path, uid, None).unwrap();
chown(&path, None, gid).unwrap();

fs::remove_file(&path).unwrap();
chown(&path, uid, gid).unwrap_err();
}

#[test]
fn test_fchownat() {
// Testing for anything other than our own UID/GID is hard.
let uid = Some(getuid());
let gid = Some(getgid());

let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path().join("file");
{
File::create(&path).unwrap();
}

let dirfd = open(tempdir.path(), OFlag::empty(), Mode::empty()).unwrap();

fchownat(Some(dirfd), "file", uid, gid, FchownatFlags::FollowSymlink).unwrap();

chdir(tempdir.path()).unwrap();
fchownat(None, "file", uid, gid, FchownatFlags::FollowSymlink).unwrap();

fs::remove_file(&path).unwrap();
fchownat(None, "file", uid, gid, FchownatFlags::FollowSymlink).unwrap_err();
}

#[test]
fn test_lseek() {
const CONTENTS: &[u8] = b"abcdef123456";
Expand Down

0 comments on commit 9bf4ab3

Please sign in to comment.