Skip to content

Commit

Permalink
add a test for failed validation
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Oct 3, 2023
1 parent 1e8781b commit acc190a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/containerd-shim-wasm/src/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ pub use path::PathResolve;

pub use crate::sandbox::stdio::Stdio;
use crate::sys::container::instance;

#[cfg(test)]
mod tests;
38 changes: 38 additions & 0 deletions crates/containerd-shim-wasm/src/container/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use anyhow::bail;

use crate::container::{Engine, RuntimeContext, Stdio};
use crate::sys::container::instance::Instance;
use crate::testing::WasiTest;

#[derive(Clone, Default)]
struct EngineFailingValidation;

impl Engine for EngineFailingValidation {
fn name() -> &'static str {
"wasi_instance"
}
fn can_handle(&self, _ctx: &impl RuntimeContext) -> anyhow::Result<()> {
bail!("can't handle");
}
fn run_wasi(&self, _ctx: &impl RuntimeContext, _stdio: Stdio) -> anyhow::Result<i32> {
Ok(0)
}
}

type InstanceFailingValidation = Instance<EngineFailingValidation>;

#[test]
#[cfg(unix)] // not yet implemented on Windows
fn test_validation_error() -> anyhow::Result<()> {
// A validation error should fail when creating the container
// as opposed to failing when starting it.

let result = WasiTest::<InstanceFailingValidation>::builder()?
.with_start_fn("foo")?
.with_wasm("/invalid_entrypoint.wasm")?
.build();

assert!(result.is_err());

Ok(())
}

0 comments on commit acc190a

Please sign in to comment.