Refactor file_path and provide helper function for store path

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-10-20 13:11:44 +02:00
parent a8b75ad2ba
commit f1b5b0915b
2 changed files with 10 additions and 1 deletions

View file

@ -55,7 +55,16 @@ pub fn stdout_of_command(mut command: Command) -> Vec<String> {
/// Create a PathBuf for a file in a TempDir
pub fn file_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf {
create_path_for(tempdir.path().to_path_buf(), path_elements)
}
pub fn store_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf {
let mut path = tempdir.path().to_path_buf();
path.push("store");
create_path_for(path, path_elements)
}
fn create_path_for(mut path: PathBuf, path_elements: &[&str]) -> PathBuf {
path_elements.iter().for_each(|el| path.push(el));
debug!("Calculated path = {:?}", path);
path

View file

@ -50,7 +50,7 @@ fn test_creating_works() {
call(&imag_home, &["test"]);
let entry_path = crate::imag::file_path(&imag_home, &["store", "test"]);
let entry_path = crate::imag::store_path(&imag_home, &["test"]);
assert!(entry_path.exists(), "Entry was not created: {:?}", entry_path);
assert!(entry_path.is_file() , "Entry is not a file: {:?}", entry_path);