add hierarchy manipulation tests

feat/vaults
Tomáš Mládek 2021-12-02 22:18:43 +01:00
parent da776bbcf3
commit 5b973ea868
1 changed files with 82 additions and 2 deletions

View File

@ -256,7 +256,10 @@ pub fn initialize_hier(pool: &DbPool) -> Result<()> {
mod tests {
use anyhow::Result;
use super::{UNode, UPath};
use crate::database::open_upend;
use tempdir::TempDir;
use super::*;
#[test]
fn test_unode_nonempty() {
@ -286,7 +289,7 @@ mod tests {
}
#[test]
fn test_validation() {
fn test_path_validation() {
let valid_path: Result<UPath> = "a/b/c/d/e/f/g".parse();
assert!(valid_path.is_ok());
@ -296,4 +299,81 @@ mod tests {
let invalid_path: Result<UPath> = "a//b/c//d/e/f///g".parse();
assert!(invalid_path.is_err());
}
#[test]
fn test_path_manipulation() {
// Initialize database
let temp_dir = TempDir::new("upend-test").unwrap();
let open_result = open_upend(&temp_dir, None, true).unwrap();
let foo_result = fetch_or_create_dir(
&open_result.pool.get().unwrap(),
None,
UNode("foo".to_string()),
true,
);
assert!(foo_result.is_ok());
let bar_result = fetch_or_create_dir(
&open_result.pool.get().unwrap(),
None,
UNode("bar".to_string()),
true,
);
assert!(bar_result.is_ok());
let bar_result = bar_result.unwrap();
let baz_result = fetch_or_create_dir(
&open_result.pool.get().unwrap(),
Some(bar_result.clone()),
UNode("baz".to_string()),
true,
);
assert!(baz_result.is_ok());
let baz_result = baz_result.unwrap();
let orphans = list_orphans(&open_result.pool.get().unwrap());
assert!(orphans.is_ok());
assert_eq!(orphans.unwrap().len(), 2);
let resolve_result = resolve_path(
&open_result.pool.get().unwrap(),
&"bar/baz".parse().unwrap(),
false,
);
assert!(resolve_result.is_ok());
assert_eq!(
resolve_result.unwrap(),
vec![bar_result.clone(), baz_result.clone()]
);
let resolve_result = resolve_path(
&open_result.pool.get().unwrap(),
&"bar/baz/bax".parse().unwrap(),
false,
);
assert!(resolve_result.is_err());
let resolve_result = resolve_path(
&open_result.pool.get().unwrap(),
&"bar/baz/bax".parse().unwrap(),
true,
);
assert!(resolve_result.is_ok());
let bax_result = fetch_or_create_dir(
&open_result.pool.get().unwrap(),
Some(baz_result.clone()),
UNode("bax".to_string()),
false,
);
assert!(bax_result.is_ok());
let bax_result = bax_result.unwrap();
assert_eq!(
resolve_result.unwrap(),
vec![bar_result, baz_result, bax_result]
);
}
}