589 lines
19 KiB
Rust
589 lines
19 KiB
Rust
mod common;
|
|
|
|
use std::sync::atomic::Ordering;
|
|
|
|
use arena_tracker_core::{
|
|
ChampionState, Error, Scope, SeasonScope, Statistics, Tracker, default_seasons, load_seasons,
|
|
};
|
|
use common::{
|
|
CATALOG, FakeChampions, FakeHistory, SELF_PUUID, jan_2026, open_tracker, played_match,
|
|
recorded_account,
|
|
};
|
|
|
|
fn statistics(tracker: &Tracker) -> Statistics {
|
|
let scope = Scope {
|
|
season: SeasonScope::Season(common::S1.into()),
|
|
format: None,
|
|
};
|
|
tracker.statistics(SELF_PUUID, &scope).unwrap()
|
|
}
|
|
|
|
fn row_names(stats: &Statistics) -> Vec<&str> {
|
|
stats
|
|
.rows
|
|
.iter()
|
|
.map(|r| r.champion.name.as_str())
|
|
.collect()
|
|
}
|
|
|
|
/// A tracker on the same database file as `open_tracker`, whose history is empty.
|
|
fn reopen(dir: &std::path::Path, champions: FakeChampions) -> Tracker {
|
|
Tracker::open(
|
|
&dir.join("arena.db"),
|
|
Box::new(FakeHistory::new(recorded_account(), vec![])),
|
|
)
|
|
.unwrap()
|
|
.with_seasons(common::seasons())
|
|
.with_champions(Box::new(champions), dir.join("portraits"))
|
|
}
|
|
|
|
#[test]
|
|
fn the_catalog_is_fetched_once_while_the_game_version_is_unchanged() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let first = FakeChampions::new("1.0", &CATALOG);
|
|
let first_calls = first.catalog_counter();
|
|
let tracker = reopen(dir.path(), first);
|
|
|
|
tracker.refresh_champions().unwrap();
|
|
tracker.refresh_champions().unwrap();
|
|
|
|
assert_eq!(first_calls.load(Ordering::SeqCst), 1);
|
|
assert_eq!(statistics(&tracker).challenge.unwrap().total, 6);
|
|
drop(tracker);
|
|
|
|
let same_version = FakeChampions::new("1.0", &CATALOG);
|
|
let same_calls = same_version.catalog_counter();
|
|
reopen(dir.path(), same_version)
|
|
.refresh_champions()
|
|
.unwrap();
|
|
assert_eq!(same_calls.load(Ordering::SeqCst), 0);
|
|
|
|
let mut grown = CATALOG.to_vec();
|
|
grown.push((777, "Newcomer", "Nouveau"));
|
|
let new_version = FakeChampions::new("2.0", &grown);
|
|
let new_calls = new_version.catalog_counter();
|
|
let tracker = reopen(dir.path(), new_version);
|
|
tracker.refresh_champions().unwrap();
|
|
assert_eq!(new_calls.load(Ordering::SeqCst), 1);
|
|
assert_eq!(statistics(&tracker).challenge.unwrap().total, 7);
|
|
}
|
|
|
|
#[test]
|
|
fn a_failing_source_leaves_the_cached_catalog_usable() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
reopen(dir.path(), FakeChampions::new("1.0", &CATALOG))
|
|
.refresh_champions()
|
|
.unwrap();
|
|
|
|
let offline = reopen(dir.path(), FakeChampions::new("2.0", &CATALOG).failing());
|
|
|
|
assert!(matches!(offline.refresh_champions(), Err(Error::Source(_))));
|
|
assert_eq!(statistics(&offline).challenge.unwrap().total, 6);
|
|
}
|
|
|
|
#[test]
|
|
fn without_any_catalog_the_page_shows_the_champions_played() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = open_tracker(dir.path(), &[played_match(1, 3, jan_2026(2, 0))]).with_champions(
|
|
Box::new(FakeChampions::new("1.0", &CATALOG).failing()),
|
|
dir.path().join("portraits"),
|
|
);
|
|
assert!(tracker.refresh_champions().is_err());
|
|
tracker.sync(common::RIOT_ID, &mut |_| {}).unwrap();
|
|
|
|
let stats = statistics(&tracker);
|
|
|
|
assert_eq!(row_names(&stats), ["Annie"]);
|
|
assert_eq!(stats.challenge.unwrap().total, 1);
|
|
}
|
|
|
|
#[test]
|
|
fn a_champion_played_but_absent_from_the_catalog_still_gets_a_row() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = open_tracker(dir.path(), &[played_match(1, 3, jan_2026(2, 0))]).with_champions(
|
|
Box::new(FakeChampions::new("1.0", &CATALOG[1..])),
|
|
dir.path().join("portraits"),
|
|
);
|
|
tracker.refresh_champions().unwrap();
|
|
tracker.sync(common::RIOT_ID, &mut |_| {}).unwrap();
|
|
|
|
let stats = statistics(&tracker);
|
|
|
|
assert_eq!(stats.rows.len(), 6);
|
|
let annie = stats.rows.iter().find(|r| r.champion.id == 1).unwrap();
|
|
assert_eq!(
|
|
(annie.champion.key.as_str(), annie.champion.name.as_str()),
|
|
("Annie", "Annie")
|
|
);
|
|
assert_eq!(annie.state, Some(ChampionState::InProgress));
|
|
assert_eq!(stats.challenge.unwrap().total, 6);
|
|
}
|
|
|
|
#[test]
|
|
fn rows_are_ordered_by_champion_name_in_french_order() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let champions = [
|
|
(1, "Zoe", "Zoé"),
|
|
(2, "Zed", "Zed"),
|
|
(11, "MasterYi", "Maître Yi"),
|
|
(3, "Nami", "Nami"),
|
|
];
|
|
let tracker = reopen(dir.path(), FakeChampions::new("1.0", &champions));
|
|
tracker.refresh_champions().unwrap();
|
|
|
|
assert_eq!(
|
|
row_names(&statistics(&tracker)),
|
|
["Maître Yi", "Nami", "Zed", "Zoé"]
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn portraits_are_downloaded_and_exposed_and_a_failed_one_is_left_out() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = reopen(
|
|
dir.path(),
|
|
FakeChampions::new("1.0", &CATALOG).without_portrait("Jinx"),
|
|
);
|
|
|
|
assert!(
|
|
statistics(&tracker)
|
|
.rows
|
|
.iter()
|
|
.all(|r| r.portrait.is_none())
|
|
);
|
|
tracker.refresh_champions().unwrap();
|
|
|
|
let stats = statistics(&tracker);
|
|
let portraits = dir.path().join("portraits");
|
|
for row in &stats.rows {
|
|
if row.champion.key == "Jinx" {
|
|
assert_eq!(row.portrait, None);
|
|
} else {
|
|
let path = portraits.join(format!("{}.png", row.champion.key));
|
|
assert_eq!(row.portrait.as_ref(), Some(&path));
|
|
assert_eq!(
|
|
std::fs::read(&path).unwrap(),
|
|
format!("png of {}", row.champion.key).into_bytes()
|
|
);
|
|
}
|
|
}
|
|
assert!(!portraits.join("Jinx.part").exists());
|
|
}
|
|
|
|
#[test]
|
|
fn only_files_count_as_portraits() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = reopen(dir.path(), FakeChampions::new("1.0", &CATALOG));
|
|
tracker.refresh_champions().unwrap();
|
|
let portraits = dir.path().join("portraits");
|
|
std::fs::remove_file(portraits.join("Jinx.png")).unwrap();
|
|
std::fs::create_dir(portraits.join("Jinx.png")).unwrap();
|
|
|
|
let stats = statistics(&tracker);
|
|
|
|
let jinx = stats
|
|
.rows
|
|
.iter()
|
|
.find(|r| r.champion.key == "Jinx")
|
|
.unwrap();
|
|
assert_eq!(jinx.portrait, None);
|
|
assert_eq!(
|
|
stats.rows.iter().filter(|r| r.portrait.is_some()).count(),
|
|
5
|
|
);
|
|
}
|
|
|
|
fn cards_dir(dir: &std::path::Path) -> std::path::PathBuf {
|
|
dir.join("portraits").join("cards")
|
|
}
|
|
|
|
fn card_files(dir: &std::path::Path) -> Vec<String> {
|
|
let mut names: Vec<String> = std::fs::read_dir(cards_dir(dir))
|
|
.unwrap()
|
|
.map(|e| e.unwrap().file_name().into_string().unwrap())
|
|
.collect();
|
|
names.sort();
|
|
names
|
|
}
|
|
|
|
#[test]
|
|
fn a_missing_card_portrait_is_downloaded_once_then_read_from_disk() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let source = FakeChampions::new("1.0", &CATALOG);
|
|
let calls = source.card_counter();
|
|
let tracker = reopen(dir.path(), source);
|
|
tracker.refresh_champions().unwrap();
|
|
assert!(
|
|
statistics(&tracker)
|
|
.rows
|
|
.iter()
|
|
.all(|r| r.card_portrait.is_none())
|
|
);
|
|
|
|
let mut saved = 0;
|
|
tracker
|
|
.refresh_card_portraits(&mut |ok| saved += usize::from(ok))
|
|
.unwrap();
|
|
|
|
assert_eq!((saved, calls.load(Ordering::SeqCst)), (6, 6));
|
|
let stats = statistics(&tracker);
|
|
for row in &stats.rows {
|
|
let path = cards_dir(dir.path()).join(format!("{}.jpg", row.champion.key));
|
|
assert_eq!(row.card_portrait.as_ref(), Some(&path));
|
|
let card = image::open(&path).unwrap();
|
|
// The 40 x 60 art is smaller than a card: cropped to the card's shape, not enlarged.
|
|
assert_eq!((card.width(), card.height()), (40, 59));
|
|
}
|
|
|
|
let mut saved_again = 0;
|
|
tracker
|
|
.refresh_card_portraits(&mut |ok| saved_again += usize::from(ok))
|
|
.unwrap();
|
|
assert_eq!((saved_again, calls.load(Ordering::SeqCst)), (0, 6));
|
|
}
|
|
|
|
#[test]
|
|
fn a_failed_card_download_leaves_no_file_and_the_next_pass_resumes() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let source = FakeChampions::new("1.0", &CATALOG);
|
|
let failure = source.card_failure();
|
|
let calls = source.card_counter();
|
|
let tracker = reopen(dir.path(), source);
|
|
tracker.refresh_champions().unwrap();
|
|
failure.store(true, Ordering::SeqCst);
|
|
|
|
let mut saved = 0;
|
|
tracker
|
|
.refresh_card_portraits(&mut |ok| saved += usize::from(ok))
|
|
.unwrap();
|
|
|
|
assert_eq!(saved, 0);
|
|
assert!(card_files(dir.path()).is_empty());
|
|
assert!(
|
|
statistics(&tracker)
|
|
.rows
|
|
.iter()
|
|
.all(|r| r.card_portrait.is_none())
|
|
);
|
|
|
|
failure.store(false, Ordering::SeqCst);
|
|
tracker
|
|
.refresh_card_portraits(&mut |ok| saved += usize::from(ok))
|
|
.unwrap();
|
|
|
|
assert_eq!(saved, 6);
|
|
assert_eq!(card_files(dir.path()).len(), 6);
|
|
// One request failed the first pass; the second asked for the six.
|
|
assert_eq!(calls.load(Ordering::SeqCst), 7);
|
|
assert!(
|
|
statistics(&tracker)
|
|
.rows
|
|
.iter()
|
|
.all(|r| r.card_portrait.is_some())
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_network_error_stops_the_card_pass_after_one_request() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let source = FakeChampions::new("1.0", &CATALOG);
|
|
let failure = source.card_failure();
|
|
let calls = source.card_counter();
|
|
let tracker = reopen(dir.path(), source);
|
|
tracker.refresh_champions().unwrap();
|
|
failure.store(true, Ordering::SeqCst);
|
|
|
|
let mut attempts = Vec::new();
|
|
tracker
|
|
.refresh_card_portraits(&mut |ok| attempts.push(ok))
|
|
.unwrap();
|
|
|
|
assert_eq!(calls.load(Ordering::SeqCst), 1);
|
|
assert_eq!(attempts, [false]);
|
|
}
|
|
|
|
#[test]
|
|
fn each_card_attempt_tells_whether_a_portrait_was_saved() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = reopen(
|
|
dir.path(),
|
|
FakeChampions::new("1.0", &CATALOG).without_portrait("Jinx"),
|
|
);
|
|
tracker.refresh_champions().unwrap();
|
|
|
|
let mut attempts = Vec::new();
|
|
tracker
|
|
.refresh_card_portraits(&mut |ok| attempts.push(ok))
|
|
.unwrap();
|
|
|
|
assert_eq!(attempts.len(), 6);
|
|
assert_eq!(attempts.iter().filter(|ok| **ok).count(), 5);
|
|
}
|
|
|
|
#[test]
|
|
fn a_card_portrait_that_cannot_be_read_is_skipped_without_a_file() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = reopen(
|
|
dir.path(),
|
|
FakeChampions::new("1.0", &CATALOG).with_card_art(b"<html>erreur</html>".to_vec()),
|
|
);
|
|
tracker.refresh_champions().unwrap();
|
|
|
|
let mut saved = 0;
|
|
tracker
|
|
.refresh_card_portraits(&mut |ok| saved += usize::from(ok))
|
|
.unwrap();
|
|
|
|
assert_eq!(saved, 0);
|
|
assert!(card_files(dir.path()).is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn one_failed_card_portrait_does_not_stop_the_others() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = reopen(
|
|
dir.path(),
|
|
FakeChampions::new("1.0", &CATALOG).without_portrait("Jinx"),
|
|
);
|
|
tracker.refresh_champions().unwrap();
|
|
|
|
let mut saved = 0;
|
|
tracker
|
|
.refresh_card_portraits(&mut |ok| saved += usize::from(ok))
|
|
.unwrap();
|
|
|
|
assert_eq!(saved, 5);
|
|
assert!(!card_files(dir.path()).contains(&"Jinx.jpg".to_string()));
|
|
let stats = statistics(&tracker);
|
|
let jinx = stats
|
|
.rows
|
|
.iter()
|
|
.find(|r| r.champion.key == "Jinx")
|
|
.unwrap();
|
|
assert_eq!(jinx.card_portrait, None);
|
|
}
|
|
|
|
#[test]
|
|
fn refreshing_card_portraits_without_a_champion_source_does_nothing() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = open_tracker(dir.path(), &[]);
|
|
|
|
tracker.refresh_card_portraits(&mut |_| {}).unwrap();
|
|
|
|
assert!(!dir.path().join("portraits").exists());
|
|
}
|
|
|
|
#[test]
|
|
fn refreshing_without_a_champion_source_does_nothing() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let tracker = open_tracker(dir.path(), &[]);
|
|
|
|
tracker.refresh_champions().unwrap();
|
|
|
|
assert!(!dir.path().join("portraits").exists());
|
|
}
|
|
|
|
#[test]
|
|
fn splash_downloads_resume_after_a_network_error_and_only_fetch_new_champions() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let source = FakeChampions::new("1", &CATALOG[..3]);
|
|
let failure = source.card_failure();
|
|
let splash_calls = source.splash_calls.clone();
|
|
let loading_calls = source.card_counter();
|
|
let tracker = reopen(dir.path(), source);
|
|
|
|
let mut attempts = Vec::new();
|
|
tracker
|
|
.refresh_champion_art(|| {}, &mut |saved| {
|
|
attempts.push(saved);
|
|
// Three cards, then one splash. The next splash loses the network.
|
|
if attempts.len() == 4 {
|
|
failure.store(true, Ordering::SeqCst);
|
|
}
|
|
})
|
|
.unwrap();
|
|
assert_eq!(attempts, [true, true, true, true, false]);
|
|
assert_eq!(splash_calls.load(Ordering::SeqCst), 2);
|
|
assert_eq!(loading_calls.load(Ordering::SeqCst), 3);
|
|
let first = statistics(&tracker)
|
|
.rows
|
|
.into_iter()
|
|
.filter_map(|r| r.splash)
|
|
.collect::<Vec<_>>();
|
|
assert_eq!(first.len(), 1);
|
|
// (59 + 40/2, 6 + 0.30*60) in a 112 x 75 splash.
|
|
assert!(
|
|
first[0].focus.x.abs_diff(71) <= 1 && first[0].focus.y.abs_diff(32) <= 1,
|
|
"{:?}",
|
|
first[0].focus
|
|
);
|
|
assert_eq!(std::fs::read(&first[0].path).unwrap(), common::splash_art());
|
|
|
|
drop(tracker);
|
|
let next = FakeChampions::new("2", &CATALOG[..4]);
|
|
let calls = next.splash_calls.clone();
|
|
let loading_calls = next.card_counter();
|
|
let tracker = reopen(dir.path(), next);
|
|
tracker
|
|
.refresh_champion_art(|| {}, &mut |ok| assert!(ok))
|
|
.unwrap();
|
|
let splashes = statistics(&tracker)
|
|
.rows
|
|
.into_iter()
|
|
.filter_map(|r| r.splash)
|
|
.collect::<Vec<_>>();
|
|
assert_eq!(splashes.len(), 4);
|
|
assert!(splashes.contains(&first[0]));
|
|
tracker
|
|
.refresh_champion_art(|| {}, &mut |_| panic!("already cached"))
|
|
.unwrap();
|
|
assert_eq!(calls.load(Ordering::SeqCst), 3);
|
|
assert_eq!(loading_calls.load(Ordering::SeqCst), 3);
|
|
}
|
|
|
|
#[test]
|
|
fn missing_loading_art_still_saves_the_original_splash_once_with_fixed_focus() {
|
|
for cached_card in [false, true] {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let catalog = &CATALOG[..1];
|
|
if cached_card {
|
|
let tracker = reopen(dir.path(), FakeChampions::new("1", catalog));
|
|
tracker.refresh_champions().unwrap();
|
|
tracker.refresh_card_portraits(&mut |_| {}).unwrap();
|
|
}
|
|
let source = FakeChampions::new("1", catalog).without_portrait("Annie");
|
|
let calls = source.splash_calls.clone();
|
|
let tracker = reopen(dir.path(), source);
|
|
tracker.refresh_champion_art(|| {}, &mut |_| {}).unwrap();
|
|
let splash = statistics(&tracker).rows.remove(0).splash.unwrap();
|
|
assert_eq!((splash.focus.x, splash.focus.y), (50, 30));
|
|
assert_eq!(std::fs::read(splash.path).unwrap(), common::splash_art());
|
|
tracker.refresh_champion_art(|| {}, &mut |_| {}).unwrap();
|
|
assert_eq!(calls.load(Ordering::SeqCst), 1);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_temporarily_unreadable_loading_image_is_retried_before_caching_the_splash() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let source = FakeChampions::new("1", &CATALOG[..1]).with_card_art(b"not a JPEG".to_vec());
|
|
let splash_calls = source.splash_calls.clone();
|
|
let tracker = reopen(dir.path(), source);
|
|
tracker.refresh_champion_art(|| {}, &mut |_| {}).unwrap();
|
|
assert!(statistics(&tracker).rows.iter().all(|r| r.splash.is_none()));
|
|
assert_eq!(splash_calls.load(Ordering::SeqCst), 0);
|
|
|
|
let tracker = reopen(dir.path(), FakeChampions::new("1", &CATALOG[..1]));
|
|
tracker
|
|
.refresh_champion_art(|| {}, &mut |saved| assert!(saved))
|
|
.unwrap();
|
|
assert!(statistics(&tracker).rows.iter().all(|r| r.splash.is_some()));
|
|
}
|
|
|
|
#[test]
|
|
fn an_offline_launch_keeps_the_cached_catalog_and_makes_no_art_requests() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
reopen(dir.path(), FakeChampions::new("1", &CATALOG))
|
|
.refresh_champions()
|
|
.unwrap();
|
|
let source = FakeChampions::new("1", &CATALOG).failing();
|
|
let cards = source.card_counter();
|
|
let splashes = source.splash_calls.clone();
|
|
let tracker = reopen(dir.path(), source);
|
|
let mut notified = false;
|
|
assert!(
|
|
tracker
|
|
.refresh_champion_art(|| notified = true, &mut |_| panic!("offline art attempt"))
|
|
.is_err()
|
|
);
|
|
assert!(notified);
|
|
assert_eq!(statistics(&tracker).rows.len(), CATALOG.len());
|
|
assert_eq!(cards.load(Ordering::SeqCst), 0);
|
|
assert_eq!(splashes.load(Ordering::SeqCst), 0);
|
|
}
|
|
|
|
#[test]
|
|
fn losing_the_network_during_cards_skips_all_splashes() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let source = FakeChampions::new("1", &CATALOG);
|
|
source.card_failure().store(true, Ordering::SeqCst);
|
|
let calls = source.splash_calls.clone();
|
|
let tracker = reopen(dir.path(), source);
|
|
let mut attempts = Vec::new();
|
|
tracker
|
|
.refresh_champion_art(|| {}, &mut |saved| attempts.push(saved))
|
|
.unwrap();
|
|
assert_eq!(attempts, [false]);
|
|
assert_eq!(calls.load(Ordering::SeqCst), 0);
|
|
open_tracker(dir.path(), &[])
|
|
.refresh_champion_art(|| {}, &mut |_| panic!("no source"))
|
|
.unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn load_seasons_writes_the_shipped_table_when_the_file_is_missing() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let path = dir.path().join("sub").join("seasons.toml");
|
|
|
|
let seasons = load_seasons(&path).unwrap();
|
|
|
|
assert_eq!(seasons, default_seasons());
|
|
assert!(
|
|
std::fs::read_to_string(&path)
|
|
.unwrap()
|
|
.contains("[[season]]")
|
|
);
|
|
assert_eq!(load_seasons(&path).unwrap(), seasons);
|
|
}
|
|
|
|
#[test]
|
|
fn load_seasons_reads_the_edited_file_sorted_by_start() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let path = dir.path().join("seasons.toml");
|
|
std::fs::write(
|
|
&path,
|
|
"[[season]]\nname = \"Plus tard\"\nstart = 2027-02-01\nofficial_track = \"Piste X\"\n\n[[season]]\nname = \"Avant\"\nstart = 2026-12-31\n",
|
|
)
|
|
.unwrap();
|
|
|
|
let seasons = load_seasons(&path).unwrap();
|
|
|
|
let summary: Vec<_> = seasons
|
|
.iter()
|
|
.map(|s| (s.name.as_str(), s.start.to_string()))
|
|
.collect();
|
|
assert_eq!(
|
|
summary,
|
|
[
|
|
("Avant", "31/12/2026".to_string()),
|
|
("Plus tard", "01/02/2027".to_string())
|
|
]
|
|
);
|
|
let tracks: Vec<_> = seasons
|
|
.iter()
|
|
.map(|s| s.official_track.as_deref())
|
|
.collect();
|
|
assert_eq!(tracks, [None, Some("Piste X")]);
|
|
}
|
|
|
|
#[test]
|
|
fn load_seasons_rejects_invalid_files() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let path = dir.path().join("seasons.toml");
|
|
for bad in [
|
|
"pas du toml",
|
|
"",
|
|
"[[season]]\nname = \"X\"\nstart = 2026-01-01T10:00:00\n",
|
|
"[[season]]\nname = \"X\"\nstart = 2026-01-01T10:00:00Z\n",
|
|
"[[season]]\nname = \"X\"\nstart = \"2026-01-01\"\n",
|
|
"[[season]]\nname = \"X\"\n",
|
|
"[[season]]\nstart = 2026-01-01\n",
|
|
] {
|
|
std::fs::write(&path, bad).unwrap();
|
|
assert!(
|
|
matches!(load_seasons(&path), Err(Error::Config(_))),
|
|
"{bad:?}"
|
|
);
|
|
}
|
|
}
|