#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DumpStatus {
InProgress,
Completed,
Failed,
}
impl DumpStatus {
pub fn as_str(self) -> &'static str {
match self {
DumpStatus::InProgress => "in_progress",
DumpStatus::Completed => "completed",
DumpStatus::Failed => "failed",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DumpTask {
pub id: String,
pub status: DumpStatus,
pub error_message: Option<String>,
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CreateDumpOutcome {
Created(DumpTask),
Exists {
id: String,
},
ExistsForOtherProject {
id: String,
project_iri: String,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dump_status_equality() {
assert_eq!(DumpStatus::InProgress, DumpStatus::InProgress);
assert_ne!(DumpStatus::InProgress, DumpStatus::Completed);
assert_ne!(DumpStatus::InProgress, DumpStatus::Failed);
assert_ne!(DumpStatus::Completed, DumpStatus::Failed);
}
#[test]
fn dump_task_construction_and_equality() {
let task = DumpTask {
id: "abc-123".into(),
status: DumpStatus::InProgress,
error_message: None,
created_at: None,
};
let cloned = task.clone();
assert_eq!(task, cloned);
let failed = DumpTask {
id: "def-456".into(),
status: DumpStatus::Failed,
error_message: Some("disk full".into()),
created_at: None,
};
assert_ne!(task, failed);
assert_eq!(failed.error_message.as_deref(), Some("disk full"));
}
#[test]
fn create_dump_outcome_variants() {
use chrono::TimeZone;
let ts = chrono::Utc.with_ymd_and_hms(2026, 5, 20, 14, 3, 0).unwrap();
let task = DumpTask {
id: "task-1".into(),
status: DumpStatus::InProgress,
error_message: None,
created_at: Some(ts),
};
let created = CreateDumpOutcome::Created(task.clone());
assert!(matches!(created, CreateDumpOutcome::Created(_)));
if let CreateDumpOutcome::Created(t) = &created {
assert_eq!(t.id, "task-1");
assert_eq!(t.created_at, Some(ts));
}
let exists = CreateDumpOutcome::Exists {
id: "existing-id".into(),
};
assert!(matches!(exists, CreateDumpOutcome::Exists { .. }));
if let CreateDumpOutcome::Exists { id } = &exists {
assert_eq!(id, "existing-id");
}
assert_ne!(created, exists);
}
#[test]
fn create_dump_outcome_exists_for_other_project_construction() {
let other = CreateDumpOutcome::ExistsForOtherProject {
id: "foreign-dump-id".into(),
project_iri: "http://rdfh.ch/projects/0002".into(),
};
assert!(matches!(
other,
CreateDumpOutcome::ExistsForOtherProject { .. }
));
if let CreateDumpOutcome::ExistsForOtherProject { id, project_iri } = &other {
assert_eq!(id, "foreign-dump-id");
assert_eq!(project_iri, "http://rdfh.ch/projects/0002");
}
let cloned = other.clone();
assert_eq!(other, cloned);
let different = CreateDumpOutcome::ExistsForOtherProject {
id: "other-id".into(),
project_iri: "http://rdfh.ch/projects/0003".into(),
};
assert_ne!(other, different);
let s = format!("{other:?}");
assert!(s.contains("ExistsForOtherProject"));
}
}