Add unit tests
This commit is contained in:
18
src/main.rs
18
src/main.rs
@ -4,12 +4,18 @@
|
||||
extern crate lazy_static;
|
||||
|
||||
mod commands;
|
||||
#[cfg(not(test))]
|
||||
mod component_models;
|
||||
mod consts;
|
||||
#[cfg(not(test))]
|
||||
mod event_handlers;
|
||||
#[cfg(not(test))]
|
||||
mod hooks;
|
||||
mod interval_parser;
|
||||
#[cfg(not(test))]
|
||||
mod models;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
mod time_parser;
|
||||
mod utils;
|
||||
|
||||
@ -33,6 +39,9 @@ use poise::serenity_prelude::{
|
||||
use sqlx::{MySql, Pool};
|
||||
use tokio::sync::{broadcast, broadcast::Sender, RwLock};
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::test::TestContext;
|
||||
#[cfg(not(test))]
|
||||
use crate::{
|
||||
commands::{
|
||||
allowed_dm, clock, clock_context_menu::clock_context_menu, command_macro, dashboard,
|
||||
@ -48,11 +57,18 @@ use crate::{
|
||||
type Database = MySql;
|
||||
|
||||
type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||
|
||||
#[cfg(test)]
|
||||
type Context<'a> = TestContext<'a>;
|
||||
|
||||
#[cfg(not(test))]
|
||||
type Context<'a> = poise::Context<'a, Data, Error>;
|
||||
|
||||
type ApplicationContext<'a> = poise::ApplicationContext<'a, Data, Error>;
|
||||
|
||||
pub struct Data {
|
||||
database: Pool<Database>,
|
||||
#[cfg(not(test))]
|
||||
recording_macros: RwLock<HashMap<(GuildId, UserId), CommandMacro>>,
|
||||
popular_timezones: Vec<Tz>,
|
||||
_broadcast: Sender<()>,
|
||||
@ -81,6 +97,7 @@ impl Display for Ended {
|
||||
impl StdError for Ended {}
|
||||
|
||||
#[tokio::main(flavor = "multi_thread")]
|
||||
#[cfg(not(test))]
|
||||
async fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
|
||||
let (tx, mut rx) = broadcast::channel(16);
|
||||
|
||||
@ -90,6 +107,7 @@ async fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
|
||||
env_logger::init();
|
||||
|
||||
|
Reference in New Issue
Block a user