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