Update backend_api to account for possibly null resource vector
This commit is contained in:
parent
12921bfcd0
commit
aa785419d8
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rdsys_backend"
|
name = "rdsys_backend"
|
||||||
authors = ["Cecylia Bocovich <cohosh@torproject.org>"]
|
authors = ["Cecylia Bocovich <cohosh@torproject.org>"]
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -54,9 +54,9 @@ impl Resource {
|
||||||
/// A ResourceDiff holds information about new, changed, or pruned resources
|
/// A ResourceDiff holds information about new, changed, or pruned resources
|
||||||
#[derive(Deserialize, PartialEq, Eq, Debug)]
|
#[derive(Deserialize, PartialEq, Eq, Debug)]
|
||||||
pub struct ResourceDiff {
|
pub struct ResourceDiff {
|
||||||
pub new: Option<HashMap<String, Vec<Resource>>>,
|
pub new: Option<HashMap<String, Option<Vec<Resource>>>>,
|
||||||
pub changed: Option<HashMap<String, Vec<Resource>>>,
|
pub changed: Option<HashMap<String, Option<Vec<Resource>>>>,
|
||||||
pub gone: Option<HashMap<String, Vec<Resource>>>,
|
pub gone: Option<HashMap<String, Option<Vec<Resource>>>>,
|
||||||
pub full_update: bool,
|
pub full_update: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,9 @@ mod tests {
|
||||||
assert_eq!(diff.gone, None);
|
assert_eq!(diff.gone, None);
|
||||||
assert_eq!(diff.full_update, true);
|
assert_eq!(diff.full_update, true);
|
||||||
if let Some(new) = diff.new {
|
if let Some(new) = diff.new {
|
||||||
assert_eq!(new["obfs2"][0].r#type, "obfs2");
|
if let Some(obfs2) = &new["obfs2"] {
|
||||||
|
assert_eq!(obfs2[0].r#type, "obfs2");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,4 +238,23 @@ mod tests {
|
||||||
};
|
};
|
||||||
assert_eq!(diff, empty_diff);
|
assert_eq!(diff, empty_diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_empty_hashmap() {
|
||||||
|
let data = r#"
|
||||||
|
{
|
||||||
|
"new": {
|
||||||
|
"obfs4": null,
|
||||||
|
"scramblesuit": []
|
||||||
|
},
|
||||||
|
"changed": null,
|
||||||
|
"gone": null,
|
||||||
|
"full_update": true
|
||||||
|
}"#;
|
||||||
|
let diff: ResourceDiff = serde_json::from_str(data).unwrap();
|
||||||
|
assert_ne!(diff.new, None);
|
||||||
|
assert_eq!(diff.changed, None);
|
||||||
|
assert_eq!(diff.gone, None);
|
||||||
|
assert_eq!(diff.full_update, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue