use super::*;
use crate::project::container;
use dev_utils::temp_dir::TempDir;
use fake::faker::filesystem::raw::FileName;
use fake::locales::EN;
use fake::Fake;
use std::fs;
#[test]
fn init_with_default_container_should_work() {
let _dir = TempDir::new().expect("setup should work");
let _cid = container::init(_dir.path()).expect("init container should work");
let file_path = _dir.path().join(FileName(EN).fake::<String>());
let _rid = init(&file_path, None).expect("init should work");
}
#[test]
fn init_with_provided_container_should_work() {
let _dir = TempDir::new().expect("setup should work");
let _cid = container::init(_dir.path()).expect("init container should work");
let file_path = PathBuf::from(FileName(EN).fake::<String>());
let _rid = init(&file_path, Some(_dir.path())).expect("init should work");
}
#[test]
#[should_panic(expected = "InvalidFilename")]
fn init_should_error_if_path_is_invalid() {
todo!("may not be a reachable condition");
}
#[test]
#[should_panic(expected = "PathNotAContainer")]
fn init_should_error_if_it_is_not_in_a_container() {
let _dir = TempDir::new().expect("setup should work");
let file_path = _dir.path().join(FileName(EN).fake::<String>());
let _file = fs::File::create(&file_path).expect("create file should work");
init(&file_path, None).unwrap();
}
#[test]
#[should_panic(expected = "FileAlreadyAsset")]
fn init_should_error_if_file_is_already_an_asset() {
let _dir = TempDir::new().expect("setup should work");
let _cid = container::init(_dir.path()).expect("init container should work");
let file_path = _dir.path().join(FileName(EN).fake::<String>());
init(&file_path, None).expect("initial init asset should work");
init(&file_path, None).unwrap();
}
#[test]
fn container_from_path_ancestor_should_work() {
let mut _dir = TempDir::new().expect("setup should work");
let _cid = container::init(_dir.path()).expect("init container should work");
let c_dir = _dir.mkdir().expect("creating child directory should work");
let a_path = c_dir.join(FileName(EN).fake::<String>());
let path =
container_from_path_ancestor(&a_path).expect("container from ancestor path should work");
assert_eq!(_dir.path(), &path, "container path should be correct");
}
#[test]
#[should_panic(expected = "ContainerNotFound")]
fn container_from_path_ancestor_should_error_if_no_container_found() {
let mut _dir = TempDir::new().expect("setup should work");
let c_dir = _dir.mkdir().expect("creating child directory should work");
let a_path = c_dir.join(FileName(EN).fake::<String>());
let _path = container_from_path_ancestor(&a_path).unwrap();
}