64 lines
1.6 KiB
Rust
64 lines
1.6 KiB
Rust
use std::{fs::File, io::Write, path::PathBuf};
|
|
|
|
use tempdir::TempDir;
|
|
|
|
use crate::{
|
|
cmd::{idx, init, ins},
|
|
parser::{key::Key, xattr::Xattr},
|
|
};
|
|
|
|
pub struct Scenario {
|
|
/// Table indexed by xattr1
|
|
pub dir1: PathBuf,
|
|
|
|
/// Table indexed by (xattr2,xattr3)
|
|
pub dir2: PathBuf,
|
|
pub key1: Key,
|
|
pub key2: Key,
|
|
pub xattr1: Xattr,
|
|
pub xattr2: Xattr,
|
|
pub xattr3: Xattr,
|
|
}
|
|
impl Default for Scenario {
|
|
fn default() -> Self {
|
|
let records_dir = TempDir::new("ghee-test-ins:records").unwrap().into_path();
|
|
let mut records_path = records_dir.clone();
|
|
records_path.push("records.json");
|
|
|
|
{
|
|
let mut w = File::create(&records_path).unwrap();
|
|
w.write_all(
|
|
br#"{"test1": 0, "test2": 1, "test3": 2}
|
|
{"test1": 10, "test2": 11, "test3": 12}"#,
|
|
)
|
|
.unwrap();
|
|
}
|
|
|
|
let dir1 = TempDir::new("ghee-test-ins:1").unwrap().into_path();
|
|
|
|
let dir2 = TempDir::new("ghee-test-ins:2").unwrap().into_path();
|
|
|
|
let key1 = Key::from(vec!["test1"]);
|
|
let xattr1 = key1.subkeys[0].clone();
|
|
|
|
let key2 = Key::from(vec!["test2", "test3"]);
|
|
let xattr2 = key2.subkeys[0].clone();
|
|
let xattr3 = key2.subkeys[1].clone();
|
|
|
|
init(&dir1, &key1, false).unwrap();
|
|
|
|
idx(&dir1, Some(&dir2), &key2, false);
|
|
|
|
ins(&dir1, &Some(records_path), false).unwrap();
|
|
|
|
Self {
|
|
dir1,
|
|
dir2,
|
|
key1,
|
|
key2,
|
|
xattr1,
|
|
xattr2,
|
|
xattr3,
|
|
}
|
|
}
|
|
}
|