From 014daee93b0eee34027e496c0beb7caed63e1085 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 3 Sep 2017 22:00:34 +0200 Subject: [PATCH] Add test for create() --- bin/core/imag-store/Cargo.toml | 15 +++++++++++++ bin/core/imag-store/src/create.rs | 36 +++++++++++++++++++++++++++++++ bin/core/imag-store/src/main.rs | 8 ++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/bin/core/imag-store/Cargo.toml b/bin/core/imag-store/Cargo.toml index a3715a61..c31f629e 100644 --- a/bin/core/imag-store/Cargo.toml +++ b/bin/core/imag-store/Cargo.toml @@ -27,3 +27,18 @@ libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } [features] early-panic = [ "libimagstore/early-panic" ] +[dev-dependencies.libimagutil] +version = "0.4.0" +path = "../../../lib/etc/libimagutil" +default-features = false +features = ["testing"] + +[dev-dependencies.libimagrt] +version = "0.4.0" +path = "../../../lib/core/libimagrt" +default-features = false +features = ["testing"] + +[dev-dependencies.toml-query] +version = "0.3" + diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs index f434ba75..68bb9667 100644 --- a/bin/core/imag-store/src/create.rs +++ b/bin/core/imag-store/src/create.rs @@ -177,3 +177,39 @@ fn string_from_raw_src(raw_src: &str) -> String { } content } + +#[cfg(test)] +mod tests { + use super::create; + + use std::path::PathBuf; + use toml_query::read::TomlValueReadExt; + use toml::Value; + + make_mock_app! { + app "imag-link"; + modulename mock; + version "0.4.0"; + with help "imag-link mocking app"; + } + use self::mock::generate_test_runtime; + + #[test] + fn test_create_simple() { + let test_name = "test_create_simple"; + let rt = generate_test_runtime(vec!["create", "-p", "test_create_simple"]).unwrap(); + + create(&rt); + + let e = rt.store().get(PathBuf::from(test_name)); + assert!(e.is_ok()); + let e = e.unwrap(); + assert!(e.is_some()); + let e = e.unwrap(); + + let version = e.get_header().read("imag.version").map(Option::unwrap).unwrap(); + assert_eq!(Value::String(String::from("0.4.0")), *version); + } + +} + diff --git a/bin/core/imag-store/src/main.rs b/bin/core/imag-store/src/main.rs index 9e5c5267..bb4d2ebc 100644 --- a/bin/core/imag-store/src/main.rs +++ b/bin/core/imag-store/src/main.rs @@ -35,13 +35,19 @@ extern crate clap; #[macro_use] extern crate log; extern crate toml; +#[cfg(test)] extern crate toml_query; #[macro_use] extern crate version; extern crate libimagrt; extern crate libimagstore; -extern crate libimagutil; #[macro_use] extern crate libimagerror; +#[cfg(test)] +#[macro_use] +extern crate libimagutil; +#[cfg(not(test))] +extern crate libimagutil; + use libimagrt::setup::generate_runtime_setup; mod create;