pub struct TestPlatform<T = ()> { /* private fields */ }testing only.Expand description
A Platform for tests: REST goes to a MockTransport, Background Work waits until
run_background, and Bot Data (T) is whatever the test gives.
Clones share everything, like an Adapter’s State.
For a bot’s own traits (a key-value store, say), implement them on TestPlatform<YourData> in
the bot’s crate, or, from an integration test (where the orphan rule forbids that), on a
newtype that forwards Platform and HasData to a TestPlatform.
Implementations§
Source§impl TestPlatform
impl TestPlatform
Sourcepub fn new() -> Self
pub fn new() -> Self
No Bot Data, the bot token bot-token, and a MockTransport answering 200 {}
Source§impl<T> TestPlatform<T>
impl<T> TestPlatform<T>
Sourcepub fn with_data<U>(self, data: U) -> TestPlatform<U>
pub fn with_data<U>(self, data: U) -> TestPlatform<U>
With data as Bot Data (HasData)
Sourcepub fn with_bot_token(self, token: Option<&str>) -> Self
pub fn with_bot_token(self, token: Option<&str>) -> Self
With token as the bot token, or none (ctx.bot() then fails)
Sourcepub fn with_transport(self, transport: MockTransport) -> Self
pub fn with_transport(self, transport: MockTransport) -> Self
With transport answering REST requests
Sourcepub fn transport(&self) -> &MockTransport
pub fn transport(&self) -> &MockTransport
The Transport, to read the requests sent
Sourcepub fn queued_work(&self) -> usize
pub fn queued_work(&self) -> usize
How much Background Work is waiting to run
Sourcepub fn run_all(&self) -> Vec<Result<(), HandlerError>>
pub fn run_all(&self) -> Vec<Result<(), HandlerError>>
Runs the waiting Background Work in order, as wait_until or a spawned task would after the
response is sent, then any it spawns in turn, until none is left; every result
Sourcepub fn run_background(&self) -> Result<(), HandlerError>
pub fn run_background(&self) -> Result<(), HandlerError>
run_all, failing with the first error
Trait Implementations§
Source§impl<T> Clone for TestPlatform<T>
impl<T> Clone for TestPlatform<T>
Source§impl Default for TestPlatform
impl Default for TestPlatform
Source§impl<T: Send + Sync + 'static> Platform for TestPlatform<T>
impl<T: Send + Sync + 'static> Platform for TestPlatform<T>
Source§type Transport = Arc<MockTransport>
type Transport = Arc<MockTransport>
rest only.Source§fn transport(&self) -> Arc<MockTransport> ⓘ
fn transport(&self) -> Arc<MockTransport> ⓘ
rest only.Source§fn spawn(&self, work: BackgroundWork)
fn spawn(&self, work: BackgroundWork)
rest only.work after the response is sent (wait_until on Cloudflare, tokio::spawn on a
hosted server), within the platform’s post-response time limit