federation-api: Break up some large assert_matches! invocations
This commit is contained in:
parent
70ef702124
commit
8f054ba39c
@ -70,7 +70,6 @@ where
|
||||
#[cfg(not(feature = "unstable-pre-spec"))]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use matches::assert_matches;
|
||||
use serde_json::{json, to_value as to_json_value};
|
||||
|
||||
use super::{deserialize, serialize};
|
||||
@ -87,15 +86,10 @@ mod tests {
|
||||
}
|
||||
]);
|
||||
|
||||
let parsed = deserialize(response).unwrap();
|
||||
|
||||
assert_matches!(
|
||||
parsed,
|
||||
RoomState { origin, auth_chain, state }
|
||||
if origin == "example.com"
|
||||
&& auth_chain.is_empty()
|
||||
&& state.is_empty()
|
||||
);
|
||||
let RoomState { origin, auth_chain, state } = deserialize(response).unwrap();
|
||||
assert_eq!(origin, "example.com");
|
||||
assert_eq!(auth_chain, vec![]);
|
||||
assert_eq!(state, vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -147,12 +141,9 @@ mod tests {
|
||||
#[test]
|
||||
fn too_long_array() {
|
||||
let json = json!([200, { "origin": "", "auth_chain": [], "state": [] }, 200]);
|
||||
assert_matches!(
|
||||
deserialize(json).unwrap(),
|
||||
RoomState { origin, auth_chain, state }
|
||||
if origin.is_empty()
|
||||
&& auth_chain.is_empty()
|
||||
&& state.is_empty()
|
||||
);
|
||||
let RoomState { origin, auth_chain, state } = deserialize(json).unwrap();
|
||||
assert_eq!(origin, "");
|
||||
assert_eq!(auth_chain, vec![]);
|
||||
assert_eq!(state, vec![]);
|
||||
}
|
||||
}
|
||||
|
@ -356,24 +356,26 @@ mod test {
|
||||
});
|
||||
|
||||
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
||||
assert_matches!(
|
||||
&edu,
|
||||
Edu::DeviceListUpdate(DeviceListUpdateContent {
|
||||
let DeviceListUpdateContent {
|
||||
user_id,
|
||||
device_id,
|
||||
device_display_name,
|
||||
stream_id,
|
||||
prev_id,
|
||||
deleted,
|
||||
keys
|
||||
}) if user_id == "@john:example.com"
|
||||
&& device_id == "QBUAZIFURK"
|
||||
&& device_display_name.as_deref() == Some("Mobile")
|
||||
&& *stream_id == uint!(6)
|
||||
&& prev_id.is_empty()
|
||||
&& *deleted == Some(false)
|
||||
&& keys.is_some()
|
||||
);
|
||||
keys,
|
||||
} = match &edu {
|
||||
Edu::DeviceListUpdate(u) => u,
|
||||
_ => panic!("Unexpected Edu variant: {:#?}", edu),
|
||||
};
|
||||
|
||||
assert_eq!(user_id, "@john:example.com");
|
||||
assert_eq!(device_id, "QBUAZIFURK");
|
||||
assert_eq!(device_display_name.as_deref(), Some("Mobile"));
|
||||
assert_eq!(*stream_id, uint!(6));
|
||||
assert_eq!(*prev_id, vec![]);
|
||||
assert_eq!(*deleted, Some(false));
|
||||
assert_matches!(keys, Some(_));
|
||||
|
||||
assert_eq!(serde_json::to_value(&edu).unwrap(), json);
|
||||
}
|
||||
@ -390,24 +392,26 @@ mod test {
|
||||
});
|
||||
|
||||
let edu = serde_json::from_value::<Edu>(json.clone()).unwrap();
|
||||
assert_matches!(
|
||||
&edu,
|
||||
Edu::DeviceListUpdate(DeviceListUpdateContent {
|
||||
let DeviceListUpdateContent {
|
||||
user_id,
|
||||
device_id,
|
||||
device_display_name,
|
||||
stream_id,
|
||||
prev_id,
|
||||
deleted,
|
||||
keys
|
||||
}) if user_id == "@john:example.com"
|
||||
&& device_id == "QBUAZIFURK"
|
||||
&& device_display_name.is_none()
|
||||
&& *stream_id == uint!(6)
|
||||
&& prev_id.is_empty()
|
||||
&& deleted.is_none()
|
||||
&& keys.is_none()
|
||||
);
|
||||
keys,
|
||||
} = match &edu {
|
||||
Edu::DeviceListUpdate(u) => u,
|
||||
_ => panic!("Unexpected Edu variant: {:#?}", edu),
|
||||
};
|
||||
|
||||
assert_eq!(user_id, "@john:example.com");
|
||||
assert_eq!(device_id, "QBUAZIFURK");
|
||||
assert_eq!(*device_display_name, None);
|
||||
assert_eq!(*stream_id, uint!(6));
|
||||
assert_eq!(*prev_id, vec![]);
|
||||
assert_eq!(*deleted, None);
|
||||
assert_matches!(keys, None);
|
||||
|
||||
assert_eq!(serde_json::to_value(&edu).unwrap(), json);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user