Add more tests for resource serialization
This commit is contained in:
parent
d5c98510db
commit
64247c1ceb
|
@ -23,7 +23,7 @@ pub struct Resource {
|
||||||
params: Option<HashMap<String, String>>,
|
params: Option<HashMap<String, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize, PartialEq, Debug)]
|
||||||
pub struct ResourceDiff {
|
pub struct ResourceDiff {
|
||||||
new: Option<HashMap<String, Vec<Resource>>>,
|
new: Option<HashMap<String, Vec<Resource>>>,
|
||||||
changed: Option<HashMap<String, Vec<Resource>>>,
|
changed: Option<HashMap<String, Vec<Resource>>>,
|
||||||
|
@ -102,6 +102,7 @@ mod tests {
|
||||||
{
|
{
|
||||||
"type": "obfs2",
|
"type": "obfs2",
|
||||||
"blocked_in": {},
|
"blocked_in": {},
|
||||||
|
"Location": null,
|
||||||
"protocol": "tcp",
|
"protocol": "tcp",
|
||||||
"address": "176.247.216.207",
|
"address": "176.247.216.207",
|
||||||
"port": 42810,
|
"port": 42810,
|
||||||
|
@ -158,6 +159,32 @@ mod tests {
|
||||||
"gone": null,
|
"gone": null,
|
||||||
"full_update": true
|
"full_update": true
|
||||||
}"#;
|
}"#;
|
||||||
let _diff: ResourceDiff = serde_json::from_str(data).unwrap();
|
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);
|
||||||
|
if let Some(new) = diff.new {
|
||||||
|
assert_eq!(new["obfs2"][0].r#type, "obfs2");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialize_empty_resource_diff() {
|
||||||
|
let data = r#"
|
||||||
|
{
|
||||||
|
"new": null,
|
||||||
|
"changed": null,
|
||||||
|
"gone": null,
|
||||||
|
"full_update": true
|
||||||
|
}"#;
|
||||||
|
let diff: ResourceDiff = serde_json::from_str(data).unwrap();
|
||||||
|
let empty_diff = ResourceDiff {
|
||||||
|
new: None,
|
||||||
|
changed: None,
|
||||||
|
gone: None,
|
||||||
|
full_update: true,
|
||||||
|
};
|
||||||
|
assert_eq!(diff, empty_diff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue