cap-std-sync: test opening a tempdir as ambient and then WasiDir

This commit is contained in:
Pat Hickey
2021-02-01 13:15:39 -08:00
parent 8b9d2c5bbb
commit a4372c8c2e
3 changed files with 22 additions and 1 deletions

1
Cargo.lock generated
View File

@@ -3075,6 +3075,7 @@ dependencies = [
"lazy_static",
"libc",
"system-interface",
"tempfile",
"tracing",
"unsafe-io",
"wasi-common",

View File

@@ -31,3 +31,6 @@ libc = "0.2"
[target.'cfg(windows)'.dependencies]
winapi = "0.3"
lazy_static = "1.4"
[dev-dependencies]
tempfile = "3.1.0"

View File

@@ -1,4 +1,4 @@
use crate::file::{filetype_from, to_sysif_fdflags, File};
use crate::file::{filetype_from, File};
use cap_fs_ext::{DirExt, MetadataExt, SystemTimeSpec};
use std::any::Any;
use std::convert::TryInto;
@@ -256,3 +256,20 @@ fn convert_systimespec(t: Option<wasi_common::SystemTimeSpec>) -> Option<SystemT
None => None,
}
}
#[cfg(test)]
mod test {
use super::Dir;
#[test]
fn scratch_dir() {
let tempdir = tempfile::Builder::new()
.prefix("cap-std-sync")
.tempdir()
.expect("create temporary dir");
let preopen_dir = unsafe { cap_std::fs::Dir::open_ambient_dir(tempdir.path()) }
.expect("open ambient temporary dir");
let preopen_dir = Dir::from_cap_std(preopen_dir);
wasi_common::WasiDir::open_dir(&preopen_dir, false, ".")
.expect("open the same directory via WasiDir abstraction");
}
}