qtcloud_devops_cli/code/
model.rs1#[derive(Debug, Clone, PartialEq, Eq)]
2pub enum SyncStatus {
3 Synced,
4 PendingPush,
5 PendingPull,
6 Conflict,
7}
8
9impl SyncStatus {
10 pub fn label(&self) -> &str {
11 match self {
12 Self::Synced => "已同步",
13 Self::PendingPush => "待推送",
14 Self::PendingPull => "待拉取",
15 Self::Conflict => "冲突",
16 }
17 }
18}
19
20#[derive(Debug, Clone)]
21pub struct ComponentStatus {
22 pub name: String,
23 pub status: SyncStatus,
24 pub ahead: usize,
25 pub behind: usize,
26}
27
28#[derive(Debug, Clone)]
29pub struct StatusReport {
30 pub root: String,
31 pub components: Vec<ComponentStatus>,
32 pub total: usize,
33 pub synced: usize,
34 pub pending: usize,
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn test_sync_status_labels() {
43 assert_eq!(SyncStatus::Synced.label(), "已同步");
44 assert_eq!(SyncStatus::PendingPush.label(), "待推送");
45 assert_eq!(SyncStatus::PendingPull.label(), "待拉取");
46 assert_eq!(SyncStatus::Conflict.label(), "冲突");
47 }
48
49 #[test]
50 fn test_sync_status_clone_eq() {
51 assert_eq!(SyncStatus::Synced, SyncStatus::Synced);
52 assert_ne!(SyncStatus::Synced, SyncStatus::PendingPush);
53 }
54
55 #[test]
56 fn test_component_status_builder() {
57 let c = ComponentStatus { name: "libs/foo".into(), status: SyncStatus::PendingPush, ahead: 3, behind: 0 };
58 assert_eq!(c.name, "libs/foo");
59 assert_eq!(c.ahead, 3);
60 }
61
62 #[test]
63 fn test_status_report_counts() {
64 let report = StatusReport {
65 root: "/tmp".into(),
66 components: vec![
67 ComponentStatus { name: "a".into(), status: SyncStatus::Synced, ahead: 0, behind: 0 },
68 ComponentStatus { name: "b".into(), status: SyncStatus::PendingPush, ahead: 1, behind: 0 },
69 ComponentStatus { name: "c".into(), status: SyncStatus::PendingPull, ahead: 0, behind: 2 },
70 ComponentStatus { name: "d".into(), status: SyncStatus::Conflict, ahead: 0, behind: 0 },
71 ],
72 total: 4,
73 synced: 1,
74 pending: 3,
75 };
76 assert_eq!(report.total, 4);
77 assert_eq!(report.synced, 1);
78 assert_eq!(report.pending, 3);
79 }
80}