Add unit tests

This commit is contained in:
jude
2024-02-24 15:01:54 +00:00
parent dd7e681285
commit 53e13844f9
6 changed files with 177 additions and 0 deletions

View File

@ -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();