refactor(tests): reformat code and update dependency management
- Reorganized import statements in adapter tests for better readability - Replaced or_insert_with(Vec::new) with or_default() in test closures - Updated Cargo.lock with new dependency versions and checksums - Added TLS features to tonic dependency configuration - Included sqlx, chrono, and uuid dependencies with specific features - Added jsonwebtoken and arc-swap as project dependencies - Reformatted assertion statements to comply with line length limits - Adjusted base64 import order in engine codec module - Updated protobuf include statement formatting
This commit is contained in:
+32
-9
@@ -1,7 +1,9 @@
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use imks::socket::adapter::{Adapter, AdapterError, BroadcastOptions, BroadcastFlags, BusMessage, LocalAdapter, SocketInfo};
|
||||
use imks::socket::adapter::{
|
||||
Adapter, AdapterError, BroadcastFlags, BroadcastOptions, BusMessage, LocalAdapter, SocketInfo,
|
||||
};
|
||||
use imks::socket::packet::Packet;
|
||||
use imks::socket::session_store::{InMemorySessionStore, SessionInfo, SessionStoreTrait};
|
||||
|
||||
@@ -10,7 +12,11 @@ async fn test_local_adapter_add_and_del() {
|
||||
let sent_packets: dashmap::DashMap<String, Vec<Packet>> = dashmap::DashMap::new();
|
||||
let sent_packets_clone = sent_packets.clone();
|
||||
let send_fn = move |engine_sid: &str, packet: &Packet| {
|
||||
sent_packets_clone.entry(engine_sid.to_string()).or_insert_with(Vec::new).value_mut().push(packet.clone());
|
||||
sent_packets_clone
|
||||
.entry(engine_sid.to_string())
|
||||
.or_default()
|
||||
.value_mut()
|
||||
.push(packet.clone());
|
||||
Ok(())
|
||||
};
|
||||
|
||||
@@ -47,10 +53,15 @@ async fn test_local_adapter_del_all() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_local_adapter_register_and_broadcast() {
|
||||
let sent_packets: Arc<dashmap::DashMap<String, Vec<Packet>>> = Arc::new(dashmap::DashMap::new());
|
||||
let sent_packets: Arc<dashmap::DashMap<String, Vec<Packet>>> =
|
||||
Arc::new(dashmap::DashMap::new());
|
||||
let sent_packets_clone = sent_packets.clone();
|
||||
let send_fn = move |engine_sid: &str, packet: &Packet| {
|
||||
sent_packets_clone.entry(engine_sid.to_string()).or_insert_with(Vec::new).value_mut().push(packet.clone());
|
||||
sent_packets_clone
|
||||
.entry(engine_sid.to_string())
|
||||
.or_default()
|
||||
.value_mut()
|
||||
.push(packet.clone());
|
||||
Ok(())
|
||||
};
|
||||
|
||||
@@ -71,10 +82,15 @@ async fn test_local_adapter_register_and_broadcast() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_local_adapter_broadcast_to_room() {
|
||||
let sent_packets: Arc<dashmap::DashMap<String, Vec<Packet>>> = Arc::new(dashmap::DashMap::new());
|
||||
let sent_packets: Arc<dashmap::DashMap<String, Vec<Packet>>> =
|
||||
Arc::new(dashmap::DashMap::new());
|
||||
let sent_packets_clone = sent_packets.clone();
|
||||
let send_fn = move |engine_sid: &str, packet: &Packet| {
|
||||
sent_packets_clone.entry(engine_sid.to_string()).or_insert_with(Vec::new).value_mut().push(packet.clone());
|
||||
sent_packets_clone
|
||||
.entry(engine_sid.to_string())
|
||||
.or_default()
|
||||
.value_mut()
|
||||
.push(packet.clone());
|
||||
Ok(())
|
||||
};
|
||||
|
||||
@@ -99,10 +115,15 @@ async fn test_local_adapter_broadcast_to_room() {
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_local_adapter_broadcast_except() {
|
||||
let sent_packets: Arc<dashmap::DashMap<String, Vec<Packet>>> = Arc::new(dashmap::DashMap::new());
|
||||
let sent_packets: Arc<dashmap::DashMap<String, Vec<Packet>>> =
|
||||
Arc::new(dashmap::DashMap::new());
|
||||
let sent_packets_clone = sent_packets.clone();
|
||||
let send_fn = move |engine_sid: &str, packet: &Packet| {
|
||||
sent_packets_clone.entry(engine_sid.to_string()).or_insert_with(Vec::new).value_mut().push(packet.clone());
|
||||
sent_packets_clone
|
||||
.entry(engine_sid.to_string())
|
||||
.or_default()
|
||||
.value_mut()
|
||||
.push(packet.clone());
|
||||
Ok(())
|
||||
};
|
||||
|
||||
@@ -340,5 +361,7 @@ fn test_is_valid_namespace() {
|
||||
|
||||
assert!(!imks::socket::namespace::is_valid_namespace(""));
|
||||
assert!(!imks::socket::namespace::is_valid_namespace("admin"));
|
||||
assert!(!imks::socket::namespace::is_valid_namespace(&"/".repeat(257)));
|
||||
assert!(!imks::socket::namespace::is_valid_namespace(
|
||||
&"/".repeat(257)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -78,7 +78,10 @@ fn test_engine_io_binary_encoding() {
|
||||
|
||||
let decoded = codec::decode_packet(&encoded).unwrap();
|
||||
assert_eq!(decoded.packet_type, PacketType::Message);
|
||||
assert_eq!(decoded.data, PacketData::Binary(vec![0x01, 0x02, 0x03, 0x04]));
|
||||
assert_eq!(
|
||||
decoded.data,
|
||||
PacketData::Binary(vec![0x01, 0x02, 0x03, 0x04])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use imks::engine::session::{generate_sid, SessionState, SessionStore, TransportType};
|
||||
use imks::engine::session::{SessionState, SessionStore, TransportType, generate_sid};
|
||||
|
||||
#[test]
|
||||
fn test_session_store_create_and_get() {
|
||||
@@ -56,7 +56,10 @@ fn test_generate_sid_format() {
|
||||
let sid = generate_sid();
|
||||
|
||||
assert_eq!(sid.len(), 20);
|
||||
assert!(sid.chars().all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-'));
|
||||
assert!(
|
||||
sid.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-')
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
Reference in New Issue
Block a user