From 0637b2d03a7682a6b4e5a884c3929ca144fcc9b6 Mon Sep 17 00:00:00 2001 From: z63d Date: Thu, 27 Feb 2025 20:13:52 +0900 Subject: [PATCH] feat: add tests of runtime options Signed-off-by: Kaita Nakamura --- .../src/sandbox/shim/local/tests.rs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/crates/containerd-shim-wasm/src/sandbox/shim/local/tests.rs b/crates/containerd-shim-wasm/src/sandbox/shim/local/tests.rs index 23d95ae14..0921aed04 100644 --- a/crates/containerd-shim-wasm/src/sandbox/shim/local/tests.rs +++ b/crates/containerd-shim-wasm/src/sandbox/shim/local/tests.rs @@ -7,7 +7,7 @@ use anyhow::Context; use chrono::{DateTime, Utc}; use containerd_shim::api::Status; use containerd_shim::event::Event; -use protobuf::MessageDyn; +use protobuf::{MessageDyn, SpecialFields}; use serde_json as json; use tempfile::tempdir; @@ -418,3 +418,38 @@ fn test_task_lifecycle() -> Result<()> { Ok(()) } + +#[test] +fn test_default_runtime_options() -> Result<()> { + let options: Option<&Any> = None; + + let config = Config::get_from_options(options).unwrap(); + + assert_eq!(config.systemd_cgroup, false); + + Ok(()) +} + +#[test] +fn test_custom_runtime_options() -> Result<()> { + let options = Options { + type_url: "runtimeoptions.v1.Options".to_string(), + config_path: "".to_string(), + config_body: "SystemdCgroup = true\n".to_string(), + }; + let req = CreateTaskRequest { + options: Some(Any { + type_url: options.type_url.clone(), + value: options.encode_to_vec(), + special_fields: SpecialFields::default(), + }) + .into(), + ..Default::default() + }; + + let config = Config::get_from_options(req.options.as_ref()).unwrap(); + + assert_eq!(config.systemd_cgroup, true); + + Ok(()) +}