use std::fmt;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Escalation {
#[default]
NotifyParent,
StopSupervisor,
}
impl fmt::Display for Escalation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let text = match self {
Self::NotifyParent => "notify_parent",
Self::StopSupervisor => "stop_supervisor",
};
f.write_str(text)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_keeps_the_supervisor_running() {
assert_eq!(Escalation::default(), Escalation::NotifyParent);
}
#[test]
fn displays_in_snake_case_like_the_other_policy_enums() {
assert_eq!(Escalation::NotifyParent.to_string(), "notify_parent");
assert_eq!(Escalation::StopSupervisor.to_string(), "stop_supervisor");
}
#[test]
fn round_trips_through_toml_as_a_config_value() {
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
struct Config {
escalation: Escalation,
}
for escalation in [Escalation::NotifyParent, Escalation::StopSupervisor] {
let config = Config { escalation };
let encoded = toml::to_string(&config).expect("Config serializes to TOML");
let decoded: Config = toml::from_str(&encoded).expect("Config deserializes from TOML");
assert_eq!(decoded, config);
}
}
}