unit tests
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful

This commit is contained in:
ModulatingForce 2024-03-21 14:01:54 -04:00
parent 619cdd1923
commit 68f9be4968

View file

@ -28,6 +28,8 @@ use std::sync::Arc;
// use futures::stream::iter; // use futures::stream::iter;
use twitch_irc::message::PrivmsgMessage; use twitch_irc::message::PrivmsgMessage;
// use casual_logger::Log;
use tokio::sync::RwLock; use tokio::sync::RwLock;
use async_trait::async_trait; use async_trait::async_trait;
@ -672,3 +674,258 @@ impl ModulesManager {
// Passing None to chnl may be a heavy operation, as this will review and look at the whole table // Passing None to chnl may be a heavy operation, as this will review and look at the whole table
} }
} }
// =====================
// =====================
// =====================
// =====================
// =====================
#[cfg(test)]
mod core_modulesmanager {
use casual_logger::Log;
use casual_logger::Extension;
use super::*;
/*
Possible Tests
[x] Test 1 - Custom ModGroup Workflow
1. affirm_in_statusdb(Experiments01,Custom)
2. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
3. set_instance_enabled(Experiments01)
4. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
5. set_ch_disabled(Experiments01,TestChannel01)
6. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
7. set_ch_enabled(Experiments01,TestChannel01) & set_ch_disabled(Experiments01,TestChannel02)
8. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
9. set_instance_disabled(Experiments01)
10. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
11. force_disable(Experiments01)
12. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
[x] Test 2 - Core ModGroup Workflow
1. affirm_in_statusdb(CoreModule01,Core)
2. modstatus(CoreModule01,TestChannel01) & modstatus(CoreModule01,TestChannel02)
3. set_instance_enabled(CoreModule01)
4. modstatus(CoreModule01,TestChannel01) & modstatus(CoreModule01,TestChannel02)
5. set_ch_disabled(CoreModule01,TestChannel01)
6. modstatus(CoreModule01,TestChannel01) & modstatus(CoreModule01,TestChannel02)
7. set_ch_enabled(CoreModule01,TestChannel01) & set_ch_disabled(CoreModule01,TestChannel02)
8. modstatus(CoreModule01,TestChannel01) & modstatus(CoreModule01,TestChannel02)
9. set_instance_disabled(CoreModule01)
10. modstatus(CoreModule01,TestChannel01) & modstatus(CoreModule01,TestChannel02)
11. force_disable(CoreModule01)
12. modstatus(CoreModule01,TestChannel01) & modstatus(CoreModule01,TestChannel02)
*/
async fn complex_workflow(
in_module: ModType ,
in_modgroup : ModGroup ,
in_chnl1 : ChType,
in_chnl2 : ChType)
{
let mgr = ModulesManager::init().await;
/*
1. affirm_in_statusdb(Experiments01,Custom)
2. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
*/
mgr.affirm_in_statusdb(in_module.clone(), in_modgroup.clone()).await;
match in_modgroup {
ModGroup::Custom => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Disabled(StatusLvl::Instance));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Disabled(StatusLvl::Instance));
},
ModGroup::Core => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
},
}
/*
3. set_instance_enabled(Experiments01)
4. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
*/
mgr.set_instance_enabled(in_module.clone()).await;
match in_modgroup {
ModGroup::Custom => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
},
ModGroup::Core => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
},
}
/*
5. set_ch_disabled(Experiments01,TestChannel01)
6. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
*/
mgr.set_ch_disabled(in_module.clone(),in_chnl1.clone()).await;
//StatusType::Disabled(StatusLvl::Ch(in_chnl1.clone()))
match in_modgroup {
ModGroup::Custom => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Disabled(StatusLvl::Ch(in_chnl1.clone())));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
},
ModGroup::Core => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
},
}
/*
7. set_ch_enabled(Experiments01,TestChannel01) & set_ch_disabled(Experiments01,TestChannel02)
8. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
*/
mgr.set_ch_enabled(in_module.clone(),in_chnl1.clone()).await;
//StatusType::Disabled(StatusLvl::Ch(in_chnl1.clone()))
match in_modgroup {
ModGroup::Custom => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Enabled(StatusLvl::Ch(in_chnl1.clone())));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
},
ModGroup::Core => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
},
}
/*
9. set_instance_disabled(Experiments01)
10. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
*/
mgr.set_instance_disabled(in_module.clone()).await;
// StatusType::Disabled(StatusLvl::Ch(in_chnl1.clone()))
match in_modgroup {
ModGroup::Custom => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Enabled(StatusLvl::Ch(in_chnl1.clone())));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Disabled(StatusLvl::Instance));
},
ModGroup::Core => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
},
}
/*
11. force_disable(Experiments01)
12. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
*/
mgr.force_disable(in_module.clone()).await;
match in_modgroup {
ModGroup::Custom => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Disabled(StatusLvl::Instance));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Disabled(StatusLvl::Instance));
},
ModGroup::Core => {
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl1.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
assert_eq!(mgr.modstatus(in_module.clone(), in_chnl2.clone()).await,
StatusType::Enabled(StatusLvl::Instance));
},
}
}
#[tokio::test]
async fn custom_modgroup_workflow() {
Log::set_file_ext(Extension::Log);
/*
[x] Test 1 - Custom ModGroup Workflow
1. affirm_in_statusdb(Experiments01,Custom)
2. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
3. set_instance_enabled(Experiments01)
4. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
5. set_ch_disabled(Experiments01,TestChannel01)
6. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
7. set_ch_enabled(Experiments01,TestChannel01) & set_ch_disabled(Experiments01,TestChannel02)
8. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
9. set_instance_disabled(Experiments01)
10. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
11. force_disable(Experiments01)
12. modstatus(Experiments01,TestChannel01) & modstatus(Experiments01,TestChannel02)
*/
let in_module = BotModule("Experiments01".to_string());
let in_modgroup = ModGroup::Custom;
let (in_chnl1,in_chnl2) =
(ChType::Channel("TestChannel01".to_string()),ChType::Channel("TestChannel02".to_string()));
complex_workflow(in_module, in_modgroup, in_chnl1, in_chnl2).await;
}
#[tokio::test]
async fn core_modgroup_workflow() {
Log::set_file_ext(Extension::Log);
let in_module = BotModule("CoreModule01".to_string());
let in_modgroup = ModGroup::Core;
let (in_chnl1,in_chnl2) =
(ChType::Channel("TestChannel01".to_string()),ChType::Channel("TestChannel02".to_string()));
complex_workflow(in_module, in_modgroup, in_chnl1, in_chnl2).await;
}
}