Add test: check whether imag-create works as expected
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
4c67450b0c
commit
ceabde799b
3 changed files with 66 additions and 0 deletions
|
@ -17,3 +17,4 @@ env_logger = "0.7"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
predicates = "1"
|
predicates = "1"
|
||||||
pretty_assertions = "0.6"
|
pretty_assertions = "0.6"
|
||||||
|
semver = "0.9"
|
||||||
|
|
|
@ -17,3 +17,67 @@
|
||||||
// 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-create
|
||||||
|
pub fn call(tempdir: &TempDir, targets: &[&str]) {
|
||||||
|
let mut bin = binary(tempdir);
|
||||||
|
|
||||||
|
// ensure that stdin is not used by the child process
|
||||||
|
bin.stdin(std::process::Stdio::inherit());
|
||||||
|
|
||||||
|
for target in targets.iter() {
|
||||||
|
bin.arg(target);
|
||||||
|
}
|
||||||
|
debug!("Command = {:?}", bin);
|
||||||
|
|
||||||
|
bin.assert().success();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn binary(tempdir: &TempDir) -> Command {
|
||||||
|
crate::imag::binary(tempdir, "imag-create")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_creating_works() {
|
||||||
|
crate::setup_logging();
|
||||||
|
let imag_home = crate::imag::make_temphome();
|
||||||
|
crate::imag_init::call(&imag_home);
|
||||||
|
|
||||||
|
call(&imag_home, &["test"]);
|
||||||
|
|
||||||
|
let entry_path = {
|
||||||
|
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.is_file() , "Entry is not a file: {:?}", entry_path);
|
||||||
|
|
||||||
|
let contents = std::fs::read_to_string(entry_path).unwrap();
|
||||||
|
let mut lines = contents.lines();
|
||||||
|
|
||||||
|
assert_eq!(lines.next(), Some("---"));
|
||||||
|
assert_eq!(lines.next(), Some("[imag]"));
|
||||||
|
{
|
||||||
|
let version_line = lines.next().unwrap();
|
||||||
|
assert!(version_line.starts_with("version = '"));
|
||||||
|
assert!(version_line.ends_with("'"));
|
||||||
|
let version = version_line.replace("version = '", "").replace("'", "");
|
||||||
|
let semver = semver::Version::parse(&version);
|
||||||
|
assert!(semver.is_ok());
|
||||||
|
assert!(!semver.unwrap().is_prerelease()); // we only want full versions in the header
|
||||||
|
|
||||||
|
}
|
||||||
|
assert_eq!(lines.next(), Some("---"));
|
||||||
|
assert_eq!(lines.next(), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ extern crate assert_cmd;
|
||||||
extern crate assert_fs;
|
extern crate assert_fs;
|
||||||
extern crate env_logger;
|
extern crate env_logger;
|
||||||
extern crate predicates;
|
extern crate predicates;
|
||||||
|
extern crate semver;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
#[macro_use] extern crate pretty_assertions;
|
#[macro_use] extern crate pretty_assertions;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue