Improve error handling, logging
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#[cfg(test)]
|
||||
mod integration_tests {
|
||||
use anyhow::Ok;
|
||||
use rota_lib::{
|
||||
config::{ToxicPair, UserConfig},
|
||||
resident::Resident,
|
||||
@@ -12,7 +13,7 @@ mod integration_tests {
|
||||
|
||||
#[fixture]
|
||||
fn minimal_config() -> UserConfig {
|
||||
UserConfig::new(2).with_residents(vec![
|
||||
UserConfig::default().with_residents(vec![
|
||||
Resident::new(1, "R1"),
|
||||
Resident::new(2, "R2"),
|
||||
Resident::new(3, "R3"),
|
||||
@@ -22,7 +23,7 @@ mod integration_tests {
|
||||
|
||||
#[fixture]
|
||||
fn maximal_config() -> UserConfig {
|
||||
UserConfig::new(2)
|
||||
UserConfig::default()
|
||||
.with_holidays(vec![2, 3, 10, 11, 12, 25])
|
||||
.with_residents(vec![
|
||||
Resident::new(1, "R1").with_max_shifts(3),
|
||||
@@ -46,7 +47,7 @@ mod integration_tests {
|
||||
|
||||
#[fixture]
|
||||
fn manual_shifts_heavy_config() -> UserConfig {
|
||||
UserConfig::new(2).with_residents(vec![
|
||||
UserConfig::default().with_residents(vec![
|
||||
Resident::new(1, "R1").with_manual_shifts(vec![
|
||||
Slot::new(Day(1), ShiftPosition::First),
|
||||
Slot::new(Day(3), ShiftPosition::First),
|
||||
@@ -65,7 +66,7 @@ mod integration_tests {
|
||||
|
||||
#[fixture]
|
||||
fn complex_config() -> UserConfig {
|
||||
UserConfig::new(2)
|
||||
UserConfig::default()
|
||||
.with_holidays(vec![5, 12, 19, 26])
|
||||
.with_residents(vec![
|
||||
Resident::new(1, "R1")
|
||||
@@ -93,43 +94,57 @@ mod integration_tests {
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_minimal_config(minimal_config: UserConfig) {
|
||||
fn test_minimal_config(minimal_config: UserConfig) -> anyhow::Result<()> {
|
||||
let mut schedule = MonthlySchedule::new();
|
||||
let mut tracker = WorkloadTracker::default();
|
||||
let scheduler = Scheduler::new_with_config(minimal_config.clone());
|
||||
|
||||
assert!(scheduler.run(&mut schedule, &mut tracker));
|
||||
assert!(scheduler.run(&mut schedule, &mut tracker)?);
|
||||
|
||||
validate_all_constraints(&schedule, &tracker, &minimal_config);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_maximal_config(maximal_config: UserConfig) {
|
||||
fn test_maximal_config(maximal_config: UserConfig) -> anyhow::Result<()> {
|
||||
let mut schedule = MonthlySchedule::new();
|
||||
let mut tracker = WorkloadTracker::default();
|
||||
let scheduler = Scheduler::new_with_config(maximal_config.clone());
|
||||
|
||||
assert!(scheduler.run(&mut schedule, &mut tracker));
|
||||
assert!(scheduler.run(&mut schedule, &mut tracker)?);
|
||||
|
||||
validate_all_constraints(&schedule, &tracker, &maximal_config);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_manual_shifts_heavy_config(manual_shifts_heavy_config: UserConfig) {
|
||||
fn test_manual_shifts_heavy_config(
|
||||
manual_shifts_heavy_config: UserConfig,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut schedule = MonthlySchedule::new();
|
||||
let mut tracker = WorkloadTracker::default();
|
||||
let scheduler = Scheduler::new_with_config(manual_shifts_heavy_config.clone());
|
||||
|
||||
assert!(scheduler.run(&mut schedule, &mut tracker));
|
||||
assert!(scheduler.run(&mut schedule, &mut tracker)?);
|
||||
|
||||
validate_all_constraints(&schedule, &tracker, &manual_shifts_heavy_config);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_complex_config(complex_config: UserConfig) {
|
||||
fn test_complex_config(complex_config: UserConfig) -> anyhow::Result<()> {
|
||||
let mut schedule = MonthlySchedule::new();
|
||||
let mut tracker = WorkloadTracker::default();
|
||||
let scheduler = Scheduler::new_with_config(complex_config.clone());
|
||||
|
||||
assert!(scheduler.run(&mut schedule, &mut tracker));
|
||||
assert!(scheduler.run(&mut schedule, &mut tracker)?);
|
||||
|
||||
validate_all_constraints(&schedule, &tracker, &complex_config);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_all_constraints(
|
||||
|
||||
Reference in New Issue
Block a user