Compare commits

..

3 Commits

Author SHA1 Message Date
Flori 1ea1c4b241
Merge 3ffb124cd4 into fe8106d2a1 2024-01-24 12:32:15 +01:00
bitfl0wer 3ffb124cd4
Add test for get_limit_config 2024-01-24 12:32:08 +01:00
bitfl0wer 57e6cb438d
Add test to hit ratelimit 2024-01-24 12:21:46 +01:00
1 changed files with 47 additions and 0 deletions

47
tests/ratelimit.rs Normal file
View File

@ -0,0 +1,47 @@
use chorus::errors::ChorusError;
use chorus::ratelimiter::ChorusRequest;
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(not(target_arch = "wasm32"), tokio::test)]
async fn get_limit_config() {
let conf = ChorusRequest::get_limits_config("http://localhost:3001/api")
.await
.unwrap();
assert!(conf.channel.max_pins > 0);
assert!(conf.channel.max_topic > 0);
assert!(conf.channel.max_webhooks > 0);
assert!(conf.guild.max_roles > 0);
assert!(conf.guild.max_channels > 0);
assert!(conf.guild.max_emojis > 0);
assert!(conf.guild.max_channels_in_category > 0);
assert!(conf.guild.max_members > 0);
assert!(conf.message.max_attachment_size > 0);
assert!(conf.message.max_bulk_delete > 0);
assert!(conf.message.max_reactions > 0);
assert!(conf.message.max_characters > 0);
assert!(conf.message.max_tts_characters == 0);
assert!(conf.user.max_guilds > 0);
assert!(conf.user.max_friends > 0);
}