Skip to content

Commit 1bcfba7

Browse files
committed
Properly allow last_snapshot and last_gc to be optional.
1 parent 6d87776 commit 1bcfba7

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/models/cvmfs_status_json.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ use crate::models::generic::MaybeRfc2822DateTime;
44

55
#[derive(Debug, Deserialize, Serialize)]
66
pub struct StatusJSON {
7-
#[serde(default = "MaybeRfc2822DateTime::default")]
8-
pub last_snapshot: MaybeRfc2822DateTime,
9-
pub last_gc: MaybeRfc2822DateTime,
7+
#[serde(default)]
8+
pub last_snapshot: Option<MaybeRfc2822DateTime>,
9+
#[serde(default)]
10+
pub last_gc: Option<MaybeRfc2822DateTime>,
1011
}
1112

1213
#[cfg(test)]
@@ -27,20 +28,41 @@ mod tests {
2728

2829
// Wed, 18 Feb 2015 23:16:09 GMT
2930
assert_eq!(
30-
status.last_snapshot.try_into_datetime().unwrap(),
31+
status.last_snapshot.unwrap().try_into_datetime().unwrap(),
3132
Some(
3233
Rfc2822DateTime::from("Fri, 21 Jun 2024 17:40:02 +0000")
3334
.try_into()
3435
.unwrap()
3536
)
3637
);
3738
assert_eq!(
38-
status.last_gc.try_into_datetime().unwrap(),
39+
status.last_gc.unwrap().try_into_datetime().unwrap(),
3940
Some(
4041
Rfc2822DateTime::from("Sun, 16 Jun 2024 00:00:59 +0000")
4142
.try_into()
4243
.unwrap()
4344
)
4445
);
4546
}
47+
48+
#[test]
49+
fn test_status_json_deserialization_missing_last_gc() {
50+
let json_data = r#"
51+
{
52+
"last_snapshot": "Fri Jun 21 17:40:02 UTC 2024"
53+
}
54+
"#;
55+
56+
let status: StatusJSON = serde_json::from_str(json_data).unwrap();
57+
58+
// Wed, 18 Feb 2015 23:16:09 GMT
59+
assert_eq!(
60+
status.last_snapshot.unwrap().try_into_datetime().unwrap(),
61+
Some(
62+
Rfc2822DateTime::from("Fri, 21 Jun 2024 17:40:02 +0000")
63+
.try_into()
64+
.unwrap()
65+
)
66+
);
67+
}
4668
}

src/models/servers.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,14 +712,18 @@ impl RepositoryOrReplica {
712712
pub struct PopulatedRepositoryOrReplica {
713713
pub name: String,
714714
pub manifest: Manifest,
715-
pub last_snapshot: MaybeRfc2822DateTime,
716-
pub last_gc: MaybeRfc2822DateTime,
715+
pub last_snapshot: Option<MaybeRfc2822DateTime>,
716+
pub last_gc: Option<MaybeRfc2822DateTime>,
717717
}
718718

719719
impl PopulatedRepositoryOrReplica {
720720
pub fn output(&self) {
721-
println!(" Last Snapshot: {}", self.last_snapshot);
722-
println!(" Last GC: {}", self.last_gc);
721+
if self.last_gc.is_some() {
722+
println!(" Last Snapshot: {}", self.last_snapshot.as_ref().unwrap());
723+
}
724+
if self.last_gc.is_some() {
725+
println!(" Last GC: {}", self.last_gc.as_ref().unwrap());
726+
}
723727
self.manifest.output();
724728
}
725729
pub fn revision(&self) -> i32 {

0 commit comments

Comments
 (0)