use tokio::test, cargo fmt/clippy
parent
b760b32bae
commit
bd50e615a7
|
@ -265,7 +265,7 @@ impl AsyncClient {
|
|||
pub fn base_client(&self) -> Arc<RwLock<BaseClient>> {
|
||||
Arc::clone(&self.base_client)
|
||||
}
|
||||
|
||||
|
||||
/// Calculate the room name from a `RoomId`, returning a string.
|
||||
pub async fn get_room_name(&self, room_id: &str) -> Option<String> {
|
||||
self.base_client.read().await.calculate_room_name(room_id)
|
||||
|
|
|
@ -72,7 +72,7 @@ pub struct RoomMember {
|
|||
/// A Matrix rooom.
|
||||
pub struct Room {
|
||||
/// The unique id of the room.
|
||||
pub room_id: RoomId,
|
||||
pub room_id: String,
|
||||
/// The name of the room, clients use this to represent a room.
|
||||
pub room_name: RoomName,
|
||||
/// The mxid of our own user.
|
||||
|
@ -203,7 +203,7 @@ impl Room {
|
|||
}
|
||||
|
||||
/// Handle a room.member updating the room state if necessary.
|
||||
///
|
||||
///
|
||||
/// Returns true if the joined member list changed, false otherwise.
|
||||
pub fn handle_membership(&mut self, event: &MemberEvent) -> bool {
|
||||
match event.content.membership {
|
||||
|
@ -234,7 +234,7 @@ impl Room {
|
|||
}
|
||||
|
||||
/// Handle a room.aliases event, updating the room state if necessary.
|
||||
///
|
||||
///
|
||||
/// Returns true if the room name changed, false otherwise.
|
||||
pub fn handle_room_aliases(&mut self, event: &AliasesEvent) -> bool {
|
||||
match event.content.aliases.as_slice() {
|
||||
|
@ -245,7 +245,7 @@ impl Room {
|
|||
}
|
||||
|
||||
/// Handle a room.canonical_alias event, updating the room state if necessary.
|
||||
///
|
||||
///
|
||||
/// Returns true if the room name changed, false otherwise.
|
||||
pub fn handle_canonical(&mut self, event: &CanonicalAliasEvent) -> bool {
|
||||
match &event.content.alias {
|
||||
|
@ -255,7 +255,7 @@ impl Room {
|
|||
}
|
||||
|
||||
/// Handle a room.name event, updating the room state if necessary.
|
||||
///
|
||||
///
|
||||
/// Returns true if the room name changed, false otherwise.
|
||||
pub fn handle_room_name(&mut self, event: &NameEvent) -> bool {
|
||||
match event.content.name() {
|
||||
|
|
|
@ -9,10 +9,8 @@ use std::convert::TryFrom;
|
|||
use std::str::FromStr;
|
||||
use std::time::Duration;
|
||||
|
||||
#[test]
|
||||
fn login() {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
|
||||
#[tokio::test]
|
||||
async fn login() {
|
||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||
|
||||
let _m = mock("POST", "/_matrix/client/r0/login")
|
||||
|
@ -22,17 +20,17 @@ fn login() {
|
|||
|
||||
let mut client = AsyncClient::new(homeserver, None).unwrap();
|
||||
|
||||
rt.block_on(client.login("example", "wordpass", None, None))
|
||||
client
|
||||
.login("example", "wordpass", None, None)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let logged_in = rt.block_on(client.logged_in());
|
||||
let logged_in = client.logged_in().await;
|
||||
assert!(logged_in, "Clint should be logged in");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync() {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
|
||||
#[tokio::test]
|
||||
async fn sync() {
|
||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||
|
||||
let session = Session {
|
||||
|
@ -53,17 +51,15 @@ fn sync() {
|
|||
|
||||
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
||||
|
||||
let response = rt.block_on(client.sync(sync_settings)).unwrap();
|
||||
let response = client.sync(sync_settings).await.unwrap();
|
||||
|
||||
assert_ne!(response.next_batch, "");
|
||||
|
||||
assert!(rt.block_on(client.sync_token()).is_some());
|
||||
assert!(client.sync_token().await.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn timeline() {
|
||||
let mut rt = Runtime::new().unwrap();
|
||||
|
||||
#[tokio::test]
|
||||
async fn timeline() {
|
||||
let homeserver = Url::from_str(&mockito::server_url()).unwrap();
|
||||
|
||||
let session = Session {
|
||||
|
@ -82,15 +78,15 @@ fn timeline() {
|
|||
|
||||
let mut client = AsyncClient::new(homeserver, Some(session)).unwrap();
|
||||
|
||||
let sync_settings = SyncSettings::new().timeout(3000).unwrap();
|
||||
let sync_settings = SyncSettings::new().timeout(Duration::from_millis(3000));
|
||||
|
||||
let _response = rt.block_on(client.sync(sync_settings)).unwrap();
|
||||
let _response = client.sync(sync_settings).await.unwrap();
|
||||
|
||||
assert_eq!(vec!["tutorial"], rt.block_on(client.get_room_names()));
|
||||
assert_eq!(vec!["tutorial"], client.get_room_names().await);
|
||||
assert_eq!(
|
||||
Some("tutorial".into()),
|
||||
rt.block_on(client.get_room_name("!SVkFJHzfwvuaIEawgC:localhost"))
|
||||
client.get_room_name("!SVkFJHzfwvuaIEawgC:localhost").await
|
||||
);
|
||||
|
||||
// rt.block_on(async { println!("{:#?}", &client.base_client().read().await.joined_rooms ) });
|
||||
println!("{:#?}", &client.base_client().read().await.joined_rooms);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue