Change T: Updateable to Arc<RwLock<T>>
This commit is contained in:
parent
bca1092dd0
commit
582d855662
|
@ -8,11 +8,11 @@ mod common;
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn get_channel() {
|
async fn get_channel() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let bundle_channel = bundle.channel.clone();
|
let bundle_channel = bundle.channel.read().unwrap();
|
||||||
let bundle_user = &mut bundle.user;
|
let bundle_user = &mut bundle.user;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bundle_channel,
|
*bundle_channel,
|
||||||
Channel::get(bundle_user, bundle_channel.id).await.unwrap()
|
Channel::get(bundle_user, bundle_channel.id).await.unwrap()
|
||||||
);
|
);
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
|
@ -21,7 +21,7 @@ async fn get_channel() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn delete_channel() {
|
async fn delete_channel() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let result = Channel::delete(bundle.channel.clone(), &mut bundle.user).await;
|
let result = Channel::delete(*bundle.channel.write().unwrap(), &mut bundle.user).await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
@ -50,16 +50,21 @@ async fn modify_channel() {
|
||||||
default_thread_rate_limit_per_user: None,
|
default_thread_rate_limit_per_user: None,
|
||||||
video_quality_mode: None,
|
video_quality_mode: None,
|
||||||
};
|
};
|
||||||
let modified_channel = Channel::modify(channel, modify_data, channel.id, &mut bundle.user)
|
let modified_channel = Channel::modify(
|
||||||
.await
|
channel.read().as_ref().unwrap(),
|
||||||
.unwrap();
|
modify_data,
|
||||||
|
channel.read().unwrap().id,
|
||||||
|
&mut bundle.user,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert_eq!(modified_channel.name, Some(CHANNEL_NAME.to_string()));
|
assert_eq!(modified_channel.name, Some(CHANNEL_NAME.to_string()));
|
||||||
|
|
||||||
let permission_override = PermissionFlags::from_vec(Vec::from([
|
let permission_override = PermissionFlags::from_vec(Vec::from([
|
||||||
PermissionFlags::MANAGE_CHANNELS,
|
PermissionFlags::MANAGE_CHANNELS,
|
||||||
PermissionFlags::MANAGE_MESSAGES,
|
PermissionFlags::MANAGE_MESSAGES,
|
||||||
]));
|
]));
|
||||||
let user_id: types::Snowflake = bundle.user.object.read().unwrap().id;
|
let user_id: types::Snowflake = bundle.user.read().unwrap().object.read().unwrap().id;
|
||||||
let permission_override = PermissionOverwrite {
|
let permission_override = PermissionOverwrite {
|
||||||
id: user_id,
|
id: user_id,
|
||||||
overwrite_type: "1".to_string(),
|
overwrite_type: "1".to_string(),
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
use chorus::gateway::Gateway;
|
use chorus::gateway::Gateway;
|
||||||
use chorus::{
|
use chorus::{
|
||||||
instance::{Instance, UserMeta},
|
instance::{Instance, UserMeta},
|
||||||
|
@ -14,9 +16,9 @@ pub(crate) struct TestBundle {
|
||||||
pub urls: UrlBundle,
|
pub urls: UrlBundle,
|
||||||
pub user: UserMeta,
|
pub user: UserMeta,
|
||||||
pub instance: Instance,
|
pub instance: Instance,
|
||||||
pub guild: Guild,
|
pub guild: Arc<RwLock<Guild>>,
|
||||||
pub role: RoleObject,
|
pub role: Arc<RwLock<RoleObject>>,
|
||||||
pub channel: Channel,
|
pub channel: Arc<RwLock<Channel>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
@ -113,17 +115,16 @@ pub(crate) async fn setup() -> TestBundle {
|
||||||
urls,
|
urls,
|
||||||
user,
|
user,
|
||||||
instance,
|
instance,
|
||||||
guild,
|
guild: Arc::new(RwLock::new(guild)),
|
||||||
role,
|
role: Arc::new(RwLock::new(role)),
|
||||||
channel,
|
channel: Arc::new(RwLock::new(channel)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Teardown method to clean up after a test.
|
// Teardown method to clean up after a test.
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) async fn teardown(mut bundle: TestBundle) {
|
pub(crate) async fn teardown(mut bundle: TestBundle) {
|
||||||
Guild::delete(&mut bundle.user, bundle.guild.id)
|
let id = bundle.guild.read().unwrap().id;
|
||||||
.await
|
Guild::delete(&mut bundle.user, id).await.unwrap();
|
||||||
.unwrap();
|
|
||||||
bundle.user.delete().await.unwrap()
|
bundle.user.delete().await.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,18 +29,30 @@ async fn test_gateway_authenticate() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_self_updating_structs() {
|
async fn test_self_updating_structs() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let channel_updater = bundle.user.gateway.observe(bundle.channel).await;
|
let channel_updater = bundle.user.gateway.observe(bundle.channel.clone()).await;
|
||||||
let received_channel = channel_updater.borrow().clone();
|
let received_channel = channel_updater.borrow().clone();
|
||||||
assert_eq!(received_channel, bundle.channel);
|
assert_eq!(
|
||||||
|
*received_channel.read().unwrap(),
|
||||||
|
*bundle.channel.read().unwrap()
|
||||||
|
);
|
||||||
let channel = &mut bundle.channel;
|
let channel = &mut bundle.channel;
|
||||||
let modify_data = types::ChannelModifySchema {
|
let modify_data = types::ChannelModifySchema {
|
||||||
name: Some("beepboop".to_string()),
|
name: Some("beepboop".to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
Channel::modify(channel, modify_data, channel.id, &mut bundle.user)
|
let channel_id = channel.read().unwrap().id;
|
||||||
.await
|
Channel::modify(
|
||||||
.unwrap();
|
channel.read().as_ref().unwrap(),
|
||||||
|
modify_data,
|
||||||
|
channel_id,
|
||||||
|
&mut bundle.user,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
let received_channel = channel_updater.borrow();
|
let received_channel = channel_updater.borrow();
|
||||||
assert_eq!(received_channel.name.as_ref().unwrap(), "beepboop");
|
assert_eq!(
|
||||||
|
received_channel.read().unwrap().name.as_ref().unwrap(),
|
||||||
|
"beepboop"
|
||||||
|
);
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue