//! What this device holds on disk. use super::*; const MINE: &str = "11111111-1111-4111-8111-111111111111"; const THEIRS: &str = "77777777-7777-4777-8777-777777777777"; fn layout_in(root: &std::path::Path) -> Layout { Layout::new(root.join("CottonDB")) } /// A replica of this device's OWN workspace, with `todos` records in it. fn own_replica(layout: &Layout, workspace: &str, todos: usize) -> PathBuf { crate::test_support::replica_with_rows(layout, workspace, todos) } #[test] fn a_device_holding_its_own_file_is_found_by_the_directory_it_lives_in() { let root = tempfile::tempdir().expect("a temp dir"); let layout = layout_in(root.path()); own_replica(&layout, MINE, 3); let held = held_workspaces(&layout, THEIRS); assert_eq!(held.len(), 1); assert_eq!(held[0].workspace_id, MINE); assert!(held[0].rows >= 4, "three todos and a workspace row"); // And it is not found when it IS the one being asked about: a start asks // "what am I holding OTHER than this". assert!(held_workspaces(&layout, MINE).is_empty()); } #[test] fn a_folder_with_no_replica_in_it_is_not_a_life() { let root = tempfile::tempdir().expect("a temp dir"); let layout = layout_in(root.path()); std::fs::create_dir_all(layout.client_dir().join("media")).expect("the media folder"); std::fs::create_dir_all(layout.client_dir().join("snapshots")).expect("the scratch folder"); assert!(held_workspaces(&layout, THEIRS).is_empty()); }