From 1451e3a1de01887917e71e284a0a8d4818a43b30 Mon Sep 17 00:00:00 2001 From: Yashodhan Joshi Date: Tue, 23 Jan 2024 11:33:47 +0530 Subject: [PATCH] Extract the runc check into a function Signed-off-by: Yashodhan Joshi --- tests/contest/contest/src/tests/domainname/mod.rs | 7 ++----- .../contest/src/tests/scheduler/scheduler_policy.rs | 12 +++--------- tests/contest/contest/src/utils/support.rs | 7 +++++++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/contest/contest/src/tests/domainname/mod.rs b/tests/contest/contest/src/tests/domainname/mod.rs index 81ad9589da..ddde3e59ff 100644 --- a/tests/contest/contest/src/tests/domainname/mod.rs +++ b/tests/contest/contest/src/tests/domainname/mod.rs @@ -1,4 +1,4 @@ -use crate::utils::test_inside_container; +use crate::utils::{support::is_runtime_runc, test_inside_container}; use oci_spec::runtime::{ProcessBuilder, Spec, SpecBuilder}; use test_framework::{ConditionalTest, TestGroup, TestResult}; @@ -27,10 +27,7 @@ pub fn get_domainname_tests() -> TestGroup { let mut tg = TestGroup::new("domainname_test"); let set_domainname_test = ConditionalTest::new( "set_domainname_test", - Box::new(|| match std::env::var("RUNTIME_KIND") { - Err(_) => true, - Ok(s) => s != "runc", - }), + Box::new(|| !is_runtime_runc()), Box::new(set_domainname_test), ); tg.add(vec![Box::new(set_domainname_test)]); diff --git a/tests/contest/contest/src/tests/scheduler/scheduler_policy.rs b/tests/contest/contest/src/tests/scheduler/scheduler_policy.rs index 431db41412..8dcbaf1fa8 100644 --- a/tests/contest/contest/src/tests/scheduler/scheduler_policy.rs +++ b/tests/contest/contest/src/tests/scheduler/scheduler_policy.rs @@ -4,7 +4,7 @@ use oci_spec::runtime::{ }; use test_framework::{test_result, ConditionalTest, TestGroup, TestResult}; -use crate::utils::test_inside_container; +use crate::utils::{support::is_runtime_runc, test_inside_container}; fn create_spec(policy: LinuxSchedulerPolicy, execute_test: &str) -> Result { let sc = SchedulerBuilder::default() @@ -48,18 +48,12 @@ pub fn get_scheduler_test() -> TestGroup { let mut scheduler_policy_group = TestGroup::new("set_scheduler_policy"); let policy_fifo_test = ConditionalTest::new( "policy_other", - Box::new(|| match std::env::var("RUNTIME_KIND") { - Err(_) => true, - Ok(s) => s != "runc", - }), + Box::new(|| !is_runtime_runc()), Box::new(scheduler_policy_other_test), ); let policy_rr_test = ConditionalTest::new( "policy_batch", - Box::new(|| match std::env::var("RUNTIME_KIND") { - Err(_) => true, - Ok(s) => s != "runc", - }), + Box::new(|| !is_runtime_runc()), Box::new(scheduler_policy_batch_test), ); diff --git a/tests/contest/contest/src/utils/support.rs b/tests/contest/contest/src/utils/support.rs index 9f735d71b7..b86f848ffd 100644 --- a/tests/contest/contest/src/utils/support.rs +++ b/tests/contest/contest/src/utils/support.rs @@ -91,3 +91,10 @@ pub fn set_config>(project_path: P, config: &Spec) -> Result<()> config.save(path)?; Ok(()) } + +pub fn is_runtime_runc() -> bool { + match std::env::var("RUNTIME_KIND") { + Err(_) => false, + Ok(s) => s == "runc", + } +}