#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConfigShowRow {
pub label: String,
pub value: String,
}
impl ConfigShowRow {
pub fn new(label: impl Into<String>, value: impl Into<String>) -> Self {
Self {
label: label.into(),
value: value.into(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DoctorSeverity {
Ok,
Warn,
Error,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ConfigDoctorFinding {
pub severity: DoctorSeverity,
pub message: String,
}
impl ConfigDoctorFinding {
#[must_use]
pub fn ok(message: impl Into<String>) -> Self {
Self {
severity: DoctorSeverity::Ok,
message: message.into(),
}
}
#[must_use]
pub fn warn(message: impl Into<String>) -> Self {
Self {
severity: DoctorSeverity::Warn,
message: message.into(),
}
}
#[must_use]
pub fn error(message: impl Into<String>) -> Self {
Self {
severity: DoctorSeverity::Error,
message: message.into(),
}
}
}
pub trait ConfigSource: Send + Sync + 'static {
fn show(&self) -> Vec<ConfigShowRow>;
fn doctor(&self) -> Vec<ConfigDoctorFinding>;
}
#[derive(Debug, Clone, Default)]
pub struct MockConfig {
pub rows: Vec<ConfigShowRow>,
pub findings: Vec<ConfigDoctorFinding>,
}
impl MockConfig {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_row(mut self, label: impl Into<String>, value: impl Into<String>) -> Self {
self.rows.push(ConfigShowRow::new(label, value));
self
}
#[must_use]
pub fn with_finding(mut self, f: ConfigDoctorFinding) -> Self {
self.findings.push(f);
self
}
}
impl ConfigSource for MockConfig {
fn show(&self) -> Vec<ConfigShowRow> {
self.rows.clone()
}
fn doctor(&self) -> Vec<ConfigDoctorFinding> {
self.findings.clone()
}
}