Add imag-init test

* Extract function to call imag-init for a tempdir path
* Simplify setup helper functions

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-10-12 16:07:17 +02:00
parent d78ab67956
commit 49af82cc68
2 changed files with 52 additions and 0 deletions

View file

@ -17,3 +17,24 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// //
use std::process::Command;
use assert_fs::fixture::TempDir;
use assert_cmd::prelude::*;
pub fn make_temphome() -> TempDir {
TempDir::new().unwrap().persist_if(std::env::var("IMAG_UI_TEST_PERSIST").is_ok())
}
pub fn binary(tempdir: &TempDir, binary_name: &str) -> Command {
let path = tempdir.path()
.to_str()
.map(String::from)
.unwrap_or_else(|| panic!("Cannot create imag home path string"));
let mut cmd = Command::cargo_bin(binary_name).unwrap();
cmd.arg("--rtp");
cmd.arg(path);
cmd
}

View file

@ -17,3 +17,34 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// //
use std::process::Command;
use assert_cmd::prelude::*;
use assert_fs::fixture::TempDir;
/// Helper to call imag-init
pub fn call(tempdir: &TempDir) {
binary(tempdir).assert().success();
}
pub fn binary(tempdir: &TempDir) -> Command {
let path = tempdir.path()
.to_str()
.map(String::from)
.unwrap_or_else(|| panic!("Cannot create imag home path string"));
let mut cmd = Command::cargo_bin("imag-init").unwrap();
cmd.arg("--path");
cmd.arg(path);
cmd
}
#[test]
fn test_init_makes_imag_dir() {
crate::setup_logging();
let imag_home = crate::imag::make_temphome();
call(&imag_home);
assert!(imag_home.path().exists(), "imag dir does not exist");
}