Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/monetize

crates/monetize-front/tests/ledger_backup.rs

//! **monetize's export off the front** (`monetize_front::ledger_backup`): the bundle carries
//! every file the export writes, and the rendered config exports
//! where the bundle reads. (The sealed store backup and the restore went in v2.0 step 1.)

use std::collections::BTreeMap;
use std::path::PathBuf;

use monetize_front::ledger_backup as lb;

fn root(name: &str) -> PathBuf {
    let d = std::env::temp_dir().join(format!("monetize-front-lb-{}-{name}", std::process::id()));
    let _ = std::fs::remove_dir_all(&d);
    std::fs::create_dir_all(&d).unwrap();
    d
}

/// **monetize exports where the backup reads** — `backup_dir` is the
/// front's, and an operator's `monetize.toml` cannot move it (gunnar-front
/// measured the render dropping it: every backup then failed [backup-export]).
#[test]
fn the_rendered_config_exports_where_the_backup_reads() {
    let r = root("render");
    let cfg = monetize_front::intake::config_with(&r, &[], &[], &BTreeMap::new());
    let operator: toml::Table = toml::from_str("backup_dir = \"/elsewhere\"\n").unwrap();
    let mut refused = Vec::new();
    let text = monetize_front::intake::render(&r, &cfg, &[], toml::Table::new(), &BTreeMap::new(), Some(operator), &mut refused).unwrap();
    let back: monetize_server::config::Config = toml::from_str(&text).unwrap();
    assert_eq!(back.backup_dir_path(), r.join(lb::BACKUP_REL), "{text}");
}

/// ★ Review #19: the bundle carries EVERY file monetize's export writes. A file
/// left out (the verdicts, the pending pushes, the nonpay journal) is a file the
/// restore refuses to do without, or worse, a state it quietly loses.
#[test]
fn the_bundle_carries_every_file_the_export_writes() {
    for f in monetize_server::backup::FILES.iter().chain([&monetize_server::backup::MANIFEST]) {
        assert!(lb::FILES.contains(f), "{f} is written by the export but never leaves the front");
    }
}