mirror of
https://github.com/containers/youki
synced 2024-05-17 21:16:30 +02:00
80f1f36ae9
* Move individual rust-oci-tests components in the tests dir We can use several things from test_framework and even integration_test for additional tests such as podman rootless and wasm tests Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com> * fix scripts and docs for the new dir structure Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com> --------- Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>
43 lines
1.1 KiB
Rust
43 lines
1.1 KiB
Rust
//! Contains definition for a tests which should be conditionally run
|
|
use crate::testable::{TestResult, Testable};
|
|
|
|
// type aliases for test function signature
|
|
type TestFn = dyn Fn() -> TestResult + Sync + Send;
|
|
// type alias for function signature for function which checks if a test can be run or not
|
|
type CheckFn = dyn Fn() -> bool + Sync + Send;
|
|
|
|
/// Basic Template structure for tests which need to be run conditionally
|
|
pub struct ConditionalTest {
|
|
/// name of the test
|
|
name: &'static str,
|
|
/// actual test function
|
|
test_fn: Box<TestFn>,
|
|
/// function to check if a test can be run or not
|
|
check_fn: Box<CheckFn>,
|
|
}
|
|
|
|
impl ConditionalTest {
|
|
/// Create a new condition test
|
|
pub fn new(name: &'static str, check_fn: Box<CheckFn>, test_fn: Box<TestFn>) -> Self {
|
|
ConditionalTest {
|
|
name,
|
|
check_fn,
|
|
test_fn,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Testable for ConditionalTest {
|
|
fn get_name(&self) -> &'static str {
|
|
self.name
|
|
}
|
|
|
|
fn can_run(&self) -> bool {
|
|
(self.check_fn)()
|
|
}
|
|
|
|
fn run(&self) -> TestResult {
|
|
(self.test_fn)()
|
|
}
|
|
}
|