From 93782fba10bdce0a911d3a2101c07e8360dc6dc6 Mon Sep 17 00:00:00 2001 From: Fedir Panasenko Date: Sat, 20 Jul 2024 23:35:34 -0400 Subject: [PATCH] Add test for adaptors losing Requester trait bounds issue --- crates/teloxide-core/src/adaptors.rs | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/crates/teloxide-core/src/adaptors.rs b/crates/teloxide-core/src/adaptors.rs index 070c1a24..f6d2ffb8 100644 --- a/crates/teloxide-core/src/adaptors.rs +++ b/crates/teloxide-core/src/adaptors.rs @@ -45,3 +45,37 @@ pub use throttle::Throttle; pub use trace::Trace; pub use parse_mode::DefaultParseMode; + +#[cfg(all( + test, + feature = "cache_me", + feature = "throttle", + feature = "trace_adaptor", + feature = "erased" +))] +// Tests composition of all possible adaptors. The goal of this test is to +// catch situations when wrapped by adaptor bot loses Requester trait bounds. +// The problem occurs because Throttle adaptor holds queue of requests, thus +// introducing requirement for all requests to also implement Clone. +mod composition_test { + use crate::{requests::RequesterExt, types::ParseMode, Bot}; + use throttle::Limits; + use trace::Settings; + + use super::*; + + // Has to be async test due to Throttle adaptor requirements + #[tokio::test] + async fn composition() { + let bot = Bot::new("TOKEN"); + + // Erased adaptor validates Requester trait bounds, so this should fail to + // compile whenever issue occurs. + let _ = bot + .throttle(Limits::default()) + .cache_me() + .trace(Settings::empty()) + .parse_mode(ParseMode::MarkdownV2) + .erase(); + } +}