Compare commits
4 Commits
3ffb124cd4
...
262a52a8e9
Author | SHA1 | Date |
---|---|---|
bitfl0wer | 262a52a8e9 | |
bitfl0wer | 3040dcc46b | |
bitfl0wer | c950288df1 | |
bitfl0wer | e073ff26c4 |
|
@ -47,6 +47,7 @@ pub struct VoiceState {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Updateable for VoiceState {
|
impl Updateable for VoiceState {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Snowflake {
|
fn id(&self) -> Snowflake {
|
||||||
if let Some(id) = self.id {
|
if let Some(id) = self.id {
|
||||||
id // ID exists: Only the case for Spacebar Server impls
|
id // ID exists: Only the case for Spacebar Server impls
|
||||||
|
|
|
@ -31,7 +31,9 @@ pub struct AutoModerationRuleUpdate {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
impl UpdateMessage<AutoModerationRule> for AutoModerationRuleUpdate {
|
impl UpdateMessage<AutoModerationRule> for AutoModerationRuleUpdate {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
Some(self.rule.id)
|
Some(self.rule.id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ impl WebSocketEvent for ChannelCreate {}
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
impl UpdateMessage<Guild> for ChannelCreate {
|
impl UpdateMessage<Guild> for ChannelCreate {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
self.channel.guild_id
|
self.channel.guild_id
|
||||||
}
|
}
|
||||||
|
@ -73,6 +74,8 @@ impl UpdateMessage<Channel> for ChannelUpdate {
|
||||||
let mut write = object_to_update.write().unwrap();
|
let mut write = object_to_update.write().unwrap();
|
||||||
*write = self.channel.clone();
|
*write = self.channel.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
Some(self.channel.id)
|
Some(self.channel.id)
|
||||||
}
|
}
|
||||||
|
@ -111,6 +114,7 @@ pub struct ChannelDelete {
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
impl UpdateMessage<Guild> for ChannelDelete {
|
impl UpdateMessage<Guild> for ChannelDelete {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
self.channel.guild_id
|
self.channel.guild_id
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,9 @@ pub struct GuildCreate {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
impl UpdateMessage<Guild> for GuildCreate {
|
impl UpdateMessage<Guild> for GuildCreate {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
match &self.d {
|
match &self.d {
|
||||||
GuildCreateDataOption::UnavailableGuild(unavailable) => Some(unavailable.id),
|
GuildCreateDataOption::UnavailableGuild(unavailable) => Some(unavailable.id),
|
||||||
|
@ -92,6 +94,7 @@ impl WebSocketEvent for GuildUpdate {}
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
impl UpdateMessage<Guild> for GuildUpdate {
|
impl UpdateMessage<Guild> for GuildUpdate {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
Some(self.guild.id)
|
Some(self.guild.id)
|
||||||
}
|
}
|
||||||
|
@ -111,6 +114,7 @@ pub struct GuildDelete {
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
impl UpdateMessage<Guild> for GuildDelete {
|
impl UpdateMessage<Guild> for GuildDelete {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
Some(self.guild.id)
|
Some(self.guild.id)
|
||||||
}
|
}
|
||||||
|
@ -225,6 +229,7 @@ impl WebSocketEvent for GuildRoleCreate {}
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
impl UpdateMessage<Guild> for GuildRoleCreate {
|
impl UpdateMessage<Guild> for GuildRoleCreate {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
Some(self.guild_id)
|
Some(self.guild_id)
|
||||||
}
|
}
|
||||||
|
@ -258,6 +263,7 @@ impl WebSocketEvent for GuildRoleUpdate {}
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
impl UpdateMessage<RoleObject> for GuildRoleUpdate {
|
impl UpdateMessage<RoleObject> for GuildRoleUpdate {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
Some(self.role.id)
|
Some(self.role.id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,6 +135,7 @@ where
|
||||||
fn update(&mut self, object_to_update: Shared<T>) {
|
fn update(&mut self, object_to_update: Shared<T>) {
|
||||||
update_object(self.get_json(), object_to_update)
|
update_object(self.get_json(), object_to_update)
|
||||||
}
|
}
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake>;
|
fn id(&self) -> Option<Snowflake>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ impl WebSocketEvent for ThreadUpdate {}
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
impl UpdateMessage<Channel> for ThreadUpdate {
|
impl UpdateMessage<Channel> for ThreadUpdate {
|
||||||
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn id(&self) -> Option<Snowflake> {
|
fn id(&self) -> Option<Snowflake> {
|
||||||
Some(self.thread.id)
|
Some(self.thread.id)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,10 @@ mod common;
|
||||||
|
|
||||||
use chorus::errors::GatewayError;
|
use chorus::errors::GatewayError;
|
||||||
use chorus::gateway::*;
|
use chorus::gateway::*;
|
||||||
use chorus::types::{self, ChannelModifySchema, IntoShared, RoleCreateModifySchema, RoleObject};
|
use chorus::types::{
|
||||||
|
self, Channel, ChannelCreateSchema, ChannelModifySchema, IntoShared, RoleCreateModifySchema,
|
||||||
|
RoleObject,
|
||||||
|
};
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
@ -36,7 +39,10 @@ async fn test_gateway_authenticate() {
|
||||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||||
async fn test_self_updating_structs() {
|
async fn test_self_updating_structs() {
|
||||||
|
// PRETTYFYME: This test is a bit of a mess, but it works. Ideally, each self-updating struct
|
||||||
|
// would have its own test.
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
|
|
||||||
let received_channel = bundle
|
let received_channel = bundle
|
||||||
.user
|
.user
|
||||||
.gateway
|
.gateway
|
||||||
|
@ -64,6 +70,34 @@ async fn test_self_updating_structs() {
|
||||||
"selfupdating".to_string()
|
"selfupdating".to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let guild = bundle
|
||||||
|
.user
|
||||||
|
.gateway
|
||||||
|
.observe_and_into_inner(bundle.guild.clone())
|
||||||
|
.await;
|
||||||
|
assert!(guild.channels.is_none());
|
||||||
|
|
||||||
|
Channel::create(
|
||||||
|
&mut bundle.user,
|
||||||
|
guild.id,
|
||||||
|
None,
|
||||||
|
ChannelCreateSchema {
|
||||||
|
name: "selfupdating2".to_string(),
|
||||||
|
channel_type: Some(types::ChannelType::GuildText),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let guild = bundle
|
||||||
|
.user
|
||||||
|
.gateway
|
||||||
|
.observe_and_into_inner(guild.into_shared())
|
||||||
|
.await;
|
||||||
|
assert!(guild.channels.is_some());
|
||||||
|
assert!(guild.channels.as_ref().unwrap().len() == 1);
|
||||||
|
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,7 @@
|
||||||
use chorus::errors::ChorusError;
|
|
||||||
use chorus::ratelimiter::ChorusRequest;
|
use chorus::ratelimiter::ChorusRequest;
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
|
||||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
|
||||||
async fn hit_ratelimit() {
|
|
||||||
let mut bundle = common::setup().await;
|
|
||||||
let mut _count = 0;
|
|
||||||
let guild = bundle.guild.read().unwrap().clone();
|
|
||||||
while _count < 1000 {
|
|
||||||
_count += 1;
|
|
||||||
match guild.channels(&mut bundle.user).await {
|
|
||||||
Err(ChorusError::RateLimited { bucket: _ }) => {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Err(_) => panic!("Hit different rate limit"),
|
|
||||||
_ => continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
common::teardown(bundle).await;
|
|
||||||
panic!("Ratelimit never triggered");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||||
async fn get_limit_config() {
|
async fn get_limit_config() {
|
||||||
|
|
Loading…
Reference in New Issue