Clean up usage of feature = "rand" in tests

This commit is contained in:
Jonas Platte 2023-08-24 16:25:14 +02:00
parent 9009ec6c3e
commit b8fdea9b18
No known key found for this signature in database
GPG Key ID: AAA7A61F696C3E0C
2 changed files with 11 additions and 12 deletions

View File

@ -55,26 +55,25 @@ impl FromIterator<(OwnedUserId, Vec<OwnedRoomId>)> for DirectEventContent {
} }
} }
#[cfg(all(test, feature = "rand"))] #[cfg(test)]
mod tests { mod tests {
use std::collections::BTreeMap; use std::collections::BTreeMap;
use serde_json::{from_value as from_json_value, json, to_value as to_json_value}; use serde_json::{from_value as from_json_value, json, to_value as to_json_value};
use super::{DirectEvent, DirectEventContent}; use super::{DirectEvent, DirectEventContent};
use crate::{server_name, RoomId, UserId}; use crate::{room_id, user_id};
#[test] #[test]
fn serialization() { fn serialization() {
let mut content = DirectEventContent(BTreeMap::new()); let mut content = DirectEventContent(BTreeMap::new());
let server_name = server_name!("ruma.io"); let alice = user_id!("@alice:ruma.io");
let alice = UserId::new(server_name); let rooms = vec![room_id!("!1:ruma.io").to_owned()];
let rooms = vec![RoomId::new(server_name)];
content.insert(alice.clone(), rooms.clone()); content.insert(alice.to_owned(), rooms.clone());
let json_data = json!({ let json_data = json!({
alice.to_string(): rooms, alice: rooms,
}); });
assert_eq!(to_json_value(&content).unwrap(), json_data); assert_eq!(to_json_value(&content).unwrap(), json_data);
@ -82,13 +81,12 @@ mod tests {
#[test] #[test]
fn deserialization() { fn deserialization() {
let server_name = server_name!("ruma.io"); let alice = user_id!("@alice:ruma.io").to_owned();
let alice = UserId::new(server_name); let rooms = vec![room_id!("!1:ruma.io").to_owned(), room_id!("!2:ruma.io").to_owned()];
let rooms = vec![RoomId::new(server_name), RoomId::new(server_name)];
let json_data = json!({ let json_data = json!({
"content": { "content": {
alice.to_string(): vec![rooms[0].to_string(), rooms[1].to_string()], alice.to_string(): rooms,
}, },
"type": "m.direct" "type": "m.direct"
}); });

View File

@ -40,10 +40,11 @@ impl DeviceId {
} }
} }
#[cfg(all(test, feature = "rand"))] #[cfg(test)]
mod tests { mod tests {
use super::{DeviceId, OwnedDeviceId}; use super::{DeviceId, OwnedDeviceId};
#[cfg(feature = "rand")]
#[test] #[test]
fn generate_device_id() { fn generate_device_id() {
assert_eq!(DeviceId::new().as_str().len(), 8); assert_eq!(DeviceId::new().as_str().len(), 8);