-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add WasiRunner file system mounting tests
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -448,4 +448,92 @@ mod tests { | |
assert_send::<WasiRunner>(); | ||
assert_sync::<WasiRunner>(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_volume_mount_without_webcs() { | ||
use std::sync::Arc; | ||
|
||
let root_fs = virtual_fs::RootFileSystemBuilder::new().build(); | ||
|
||
let tokrt = tokio::runtime::Handle::current(); | ||
|
||
let hostdir = virtual_fs::host_fs::FileSystem::new(tokrt.clone(), "/").unwrap(); | ||
let hostdir_dyn: Arc<dyn virtual_fs::FileSystem + Send + Sync> = Arc::new(hostdir); | ||
|
||
root_fs | ||
.mount("/host".into(), &hostdir_dyn, "/".into()) | ||
.unwrap(); | ||
|
||
let envb = crate::runners::wasi::WasiRunner::new(); | ||
|
||
let annotations = webc::metadata::annotations::Wasi::new("test"); | ||
|
||
let tm = Arc::new(crate::runtime::task_manager::tokio::TokioTaskManager::new( | ||
tokrt.clone(), | ||
)); | ||
let rt = crate::PluggableRuntime::new(tm); | ||
|
||
let envb = envb | ||
.prepare_webc_env("test", &annotations, None, Arc::new(rt), Some(root_fs)) | ||
.unwrap(); | ||
|
||
let init = envb.build_init().unwrap(); | ||
|
||
let fs = &init.state.fs.root_fs; | ||
|
||
fs.read_dir(&std::path::Path::new("/host")).unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_volume_mount_with_webcs() { | ||
use std::sync::Arc; | ||
|
||
let root_fs = virtual_fs::RootFileSystemBuilder::new().build(); | ||
|
||
let tokrt = tokio::runtime::Handle::current(); | ||
|
||
let hostdir = virtual_fs::host_fs::FileSystem::new(tokrt.clone(), "/").unwrap(); | ||
let hostdir_dyn: Arc<dyn virtual_fs::FileSystem + Send + Sync> = Arc::new(hostdir); | ||
|
||
root_fs | ||
.mount("/host".into(), &hostdir_dyn, "/".into()) | ||
.unwrap(); | ||
|
||
let envb = crate::runners::wasi::WasiRunner::new(); | ||
|
||
let annotations = webc::metadata::annotations::Wasi::new("test"); | ||
|
||
let tm = Arc::new(crate::runtime::task_manager::tokio::TokioTaskManager::new( | ||
tokrt.clone(), | ||
)); | ||
let mut rt = crate::PluggableRuntime::new(tm); | ||
rt.set_package_loader(crate::runtime::package_loader::BuiltinPackageLoader::new()); | ||
|
||
let webc_path = std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("../../tests/integration/cli/tests/webc/[email protected]"); | ||
let webc_data = std::fs::read(webc_path).unwrap(); | ||
let container = webc::Container::from_bytes(webc_data).unwrap(); | ||
|
||
let binpkg = crate::bin_factory::BinaryPackage::from_webc(&container, &rt) | ||
.await | ||
.unwrap(); | ||
|
||
let mut envb = envb | ||
.prepare_webc_env( | ||
"test", | ||
&annotations, | ||
Some(&binpkg), | ||
Arc::new(rt), | ||
Some(root_fs), | ||
) | ||
.unwrap(); | ||
|
||
envb = envb.preopen_dir("/host").unwrap(); | ||
|
||
let init = envb.build_init().unwrap(); | ||
|
||
let fs = &init.state.fs.root_fs; | ||
|
||
fs.read_dir(&std::path::Path::new("/host")).unwrap(); | ||
fs.read_dir(&std::path::Path::new("/settings")).unwrap(); | ||
} | ||
} |
Binary file not shown.