use crate::runtime::phase::step::StepContext;
use crate::runtime::phase::Phase;
pub trait Action: Send + 'static {
fn label(&self) -> &'static str;
fn validate(&self, _phase: Phase) -> Result<(), String> {
Ok(())
}
fn apply(self: Box<Self>, step: &mut StepContext<'_>);
}
#[cfg(test)]
mod tests {
use super::*;
struct DummyAction;
impl Action for DummyAction {
fn label(&self) -> &'static str {
"dummy"
}
fn validate(&self, phase: Phase) -> Result<(), String> {
if phase == Phase::RunStart {
Err("not allowed in RunStart".into())
} else {
Ok(())
}
}
fn apply(self: Box<Self>, _step: &mut StepContext<'_>) {
}
}
#[test]
fn action_label() {
let action = DummyAction;
assert_eq!(action.label(), "dummy");
}
#[test]
fn action_validate_ok() {
let action = DummyAction;
assert!(action.validate(Phase::BeforeInference).is_ok());
}
#[test]
fn action_validate_err() {
let action = DummyAction;
assert!(action.validate(Phase::RunStart).is_err());
}
}