From 0a2fea7bcb14789ccba83ad50e23017ee94a22fd Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Wed, 28 Dec 2022 17:42:59 +0000 Subject: [PATCH] Test ServerLoggedInContext::new(). --- client/src/server/context.rs | 51 +++++++++++++++++++++++++++++++++++ client/src/server/room/map.rs | 4 +-- client/src/server/user/map.rs | 2 +- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/client/src/server/context.rs b/client/src/server/context.rs index b4e9723..366787c 100644 --- a/client/src/server/context.rs +++ b/client/src/server/context.rs @@ -224,3 +224,54 @@ impl ServerContext { } } } + +#[cfg(test)] +mod tests { + use solstice_proto::{User, UserStatus}; + use tokio::sync::mpsc::channel; + + use crate::server::room::{RoomMap, RoomState, RoomVisibility}; + use crate::server::user::UserMap; + + use super::{ServerLoggedInContext, ServerLoggedInContextOptions}; + + #[test] + fn server_logged_in_context_new() { + let mut rooms = RoomMap::default(); + rooms.insert( + "foo".to_string(), + RoomState::new(RoomVisibility::Public, 42), + ); + + let mut users = UserMap::default(); + users.insert(User { + name: "kim".to_string(), + status: UserStatus::Online, + average_speed: 1, + num_downloads: 2, + unknown: 3, + num_files: 4, + num_folders: 5, + num_free_slots: 6, + country: "KR".to_string(), + }); + + let (tx, _rx) = channel(100); + + let context = ServerLoggedInContext::new( + tx.clone(), + ServerLoggedInContextOptions { + users: users.clone(), + rooms: rooms.clone(), + user_name: "bob".to_string(), + motd: "hey".to_string(), + }, + ); + + assert_eq!(context.user_name(), "bob"); + assert_eq!(context.motd(), "hey"); + assert!(context.request_tx.same_channel(&tx)); + assert_eq!(context.rooms, rooms); + assert_eq!(context.users, users); + } +} diff --git a/client/src/server/room/map.rs b/client/src/server/room/map.rs index d715680..65cb802 100644 --- a/client/src/server/room/map.rs +++ b/client/src/server/room/map.rs @@ -21,7 +21,7 @@ pub struct RoomMembershipChangeError(RoomMembership, RoomMembership); pub struct RoomNotFoundError(String); /// An entry in the chat room map. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct RoomEntry { name: String, state: RoomState, @@ -138,7 +138,7 @@ impl RoomEntry { /// Contains the mapping from room names to room data and provides a clean /// interface to interact with it. -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct RoomMap { /// The actual map from room names to room data. map: HashMap, diff --git a/client/src/server/user/map.rs b/client/src/server/user/map.rs index 881c360..73b0f50 100644 --- a/client/src/server/user/map.rs +++ b/client/src/server/user/map.rs @@ -11,7 +11,7 @@ pub struct UserNotFoundError(String); /// Contains the mapping from user names to user data and provides a clean /// interface to interact with it. -#[derive(Clone, Debug, Default)] +#[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct UserMap { /// The actual map from user names to user data and privileged status. map: collections::HashMap,