Move path calculation to helper function

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-10-13 13:07:07 +02:00
parent 4cbcdc118c
commit fd2afad72a
2 changed files with 24 additions and 8 deletions

View file

@ -18,6 +18,7 @@
// //
use std::process::Command; use std::process::Command;
use std::path::PathBuf;
use assert_fs::fixture::TempDir; use assert_fs::fixture::TempDir;
use assert_cmd::prelude::*; use assert_cmd::prelude::*;
@ -38,3 +39,25 @@ pub fn binary(tempdir: &TempDir, binary_name: &str) -> Command {
cmd cmd
} }
/// Run the passed command and get the stdout of it.
///
/// This function does _not_ ensure that stdin is inherited.
pub fn stdout_of_command(command: Command) -> Vec<String> {
let assert = command.assert();
let lines = String::from_utf8(assert.get_output().stdout.clone())
.unwrap()
.lines()
.map(String::from)
.collect();
assert.success();
lines
}
/// Create a PathBuf for a file in a TempDir
pub fn file_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf {
let mut path = tempdir.path().to_path_buf();
path_elements.iter().for_each(|el| path.push(el));
debug!("Calculated path = {:?}", path);
path
}

View file

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